77范文网 - 专业文章范例文档资料分享平台

sas读入数据全解析(5)

来源:网络收集 时间:2021-09-24 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

proc import datafile="auto2.xls" out=auto1 replace;

sheet="page2";

run;

Example 3: Reading a file without variable names

What if the variables in your Excel file do not have variable names? The answer here is to use the statement getnames=no in proc import. Here is an example showing how to do this.

proc import datafile="a:\faq\auto.xls" out=auto replace;

getnames=no;

run;

Writing Excel files out from SAS

It is very easy to write out an Excel file using proc export in SAS version 8. Consider the following sample data file below.

Obs MAKE MPG WEIGHT PRICE

1 AMC 22 2930 4099

2 AMC 17 3350 4749

3 AMC 22 2640 3799

4 Buick 20 3250 4816

5 Buick 15 4080 7827

Here is a sample program that writes out an Excel file called mydata.xls into the directory

"c:\dissertation".

proc export data=mydata outfile='c:\dissertation\mydata.xls' replace;

run;

SAS读入复杂分隔数据——字符长度不同,字符中间有空格作为间隔符

1.字符长度不同

data web;

length site $41;

input age site $ hits;

datalines;

12 /default.htm 123456

130 /index.htm 97654

254 http://www.site3.edu/department/index.htm 987654

;

proc print;

run;

Obs site age hits

1 /default.htm 12 123456

2 /index.htm 130 97654

3 http://www.site3.edu/department/index.htm 254 987654

或者用

data web;

input age site & $41. hits;

datalines;

12 /default.htm 123456

130 /index.htm 97654

254 http://www.site3.edu/department/index.htm 987654

;

proc print;

run;

Obs age site hits

1 12 /default.htm 123456

2 130 /index.htm 97654

3 254 http://www.site3.edu/department/index.htm 987654

2.字符有多个单词,单词之间用空格隔开

data fruit;

infile 'C:\messy.txt' delimiter = ' ' dsd;

length fruit $22;

input zip fruit $ pounds;

proc print;

run;

Obs fruit zip pounds

1 apples, grapes kiwi 10034 123456

2 oranges 92626 97654

3 pears apple 25414 987654

或者

data fruit;

input zip fruit & $22. pounds;

datalines;

10034 apples, grapes kiwi 123456

92626 oranges 97654

25414 pears apple 987654

;

proc print;

run;

Obs zip fruit pounds

1 10034 apples, grapes kiwi 123456

2 92626 oranges 97654

3 25414 pears apple 987654

没有格式库的情况下读入数据:

read a SAS data file when I don't have its format library

If you try to use a SAS data file that has permanent formats but you don't have the format library, you will get errors like this.

ERROR: The format $MAKEF was not found or could not be loaded.

ERROR: The format FORGNF was not found or could not be loaded.

Without the format library, SAS will not permit you to do anything with the data file. However, if you use options nofmterr; at the top of your program, SAS will go ahead and process the file despite the fact that it does not have the format library. You will not be able to see the formatted values for your variables, but you will be able to process your data file. Here is an example.

OPTIONS nofmterr;

libname in "c:\";

PROC FREQ DATA=in.auto;

TABLES foreign make;

RUN;

高效的保留或者去掉部分变量的方式:

The following program creates exactly the same file, but is a more efficient program because SAS only reads the desired variables.

DATA auto2;

SET auto (KEEP = make mpg price);

RUN;

The drop data step option works in a similar way.

DATA AUTO2;

SET auto (DROP = rep78 hdroom trunk weight length

turn displ gratio foreign);

RUN;

比较双份录入的差异是否存在:

proc compare base = person1 compare = person2 brief;

by id;

id id;

run;

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说医药卫生sas读入数据全解析(5)在线全文阅读。

sas读入数据全解析(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/yiyao/1251018.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: