《sas习题运行结果》由会员分享,可在线阅读,更多相关《sas习题运行结果(6页珍藏版)》请在金锄头文库上搜索。
1、程序:简短数据运用datalines 或 cards直接输入数据进行运算。运行结果:方法二:运用format 读入数据;运行结果: You see here that there is a colon preceding each informat. This colon (called an informat modifier) tells SAS to use the informat supplied but to stop reading the value for this variable when a delimiter is encountered. Do not forget
2、 the colons because without them. SAS may read past a delimiter to satisfy the width specified in the informat. Colon: 冒号; delimiter:定界符(在这里定界符是空格);冒号的作用是从下一个非空的字符开始,读到下一个空格或者是informat指定的长度为止。libname learn “E:/SAS1/chapter4“; data learn.Perm; input ID : 3. Gender : 1. DOB : mmddyy10. Height Weight;
3、label DOB=“Date of Birth“ Height=“Height in inches“ Weight=“Weight in pounds“; format DOB date9.; datalines; 001 M 10/21/1946 68 150 002 F 5/26/1950 63 122 003 M 5/11/1981 72 175 004 M 7/4/1983 70 128 005 F 12/25/2005 30 40 ; run; title “Listing of Information“; proc print data=learn.Perm; run;如果吧 I
4、D 和 GENDER 的两个冒号去掉,那SAS 读记录的时候,1. ID 只会读取 informat中指定的长度,即前三个字符(如果每行数据前没有空格,那的值是正常的);2. GENDER 会是接下来的一个字符,而不会跳过空格, 所以 GENDER 不会读到 F 和 M这两个值。事实上,这里不用format 语句也可以正确输出gender。只有当数据集中出现sas不能读的格式时, 才需要用到format 或者 informat 。 如日期:1/1/1995 可以用format date9.将它表示为01Jan1995;如$12345,可以用format dollar5. 将它表示成$12345
5、; 第二题:程序:运行结果:Csv(comma separated values)。后缀为 .csv 的文件就是一种特殊格式的纯文本文件,即是一组字符序列,字符之间以英文字符的逗号或制表符(Tab)分隔。可 以 使 用 记 事 本 创 建CSV文 件 。 在 保 存 时 直 接 将 后 缀 改 为 .csv即 可 。第四题:程序:结果:第五题:You want to create a test data set that uses a DATALINES statement to read in values for X and Y. In the DATA step, you want to create a new variable, Z, equal to 100 + 50X + 2X2 25Y + Y2. Use the following (X,Y) data pairs: (1,2), (3,6), (5,9), and (9,11). 程序:结果: