
正文
sas简单使用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1 数据存取:
逻辑库: libname 自己起的名字 ‘文件所在的路径’,若无这步数据则存在默认的work中。
另一个方法在sas里自己建立一个逻辑库,但是关闭后就消失了。
新建数据:data 表名
引用数据:set 表名
不区分大小写 libname diabete 'C:\Users\lenovo\Desktop\sas_program'; /*diabete :自己起的逻辑库名字*/ data diabete.diabetes_female; /*diabetes_female:自己起的表名*/ set diabete.diabetes(keep=id sex age); /*diabetes:使用的表名,也就是数据来源, keep:需要保留的字段, drop:舍弃的,默认是全有的*/ length Group $ 8 /* length:变量起名,group:自己起的字段名,8字符*/ if age>=55 then group='Seniors'; /*if then else*/ else group='Under 55';price = 44.7 /*常量正常赋值*/ run;
2 筛选数据的语句:
* if , select(存在互斥的条件时)
*比较运算符和逻辑运算符:
3 日期的处理(sas默认格式为数字)
日期:初始值为1960-1-1
时间值:午夜12点算起,0-86400
例子:打印出
表单为:
3.
实现如下
/*************************************/ /* set system options for report */ /*************************************/ options nodate nonumber; /*************************************/ /* create temporary data set */ /*************************************/ data test; Time1=86399; format Time1 datetime.; Date1=86399; format Date1 date.; Time2=86399; format Time2 timeampm.; Date1Month=month(Date1); run; /*************************************/ /* print data set */ /*************************************/ proc print data=test noobs; title 'Same Number, Different SAS Values'; footnote1 'Time1 is a SAS DATETIME value.'; footnote2 'Date1 is a SAS DATE value.'; footnote3 'Time2 is a SAS TIME value.'; footnote4 'Date1Month is the numeric month for Date1.'; run; /*************************************/ /* clear any titles and footnotes */ /* in effect 实际没看出差别 */ /*************************************/ title; footnote;
3 打印:
/*************************************/
/* set system options for report */
/*************************************/
options nodate pageno=1 linesize=64 pagesize=60;
/*************************************/
/* sort the data and create a */
/* temporary output data set */
/*************************************/
proc sort data=pilots out=tempemp;
by jobcode gender;
run;
/*************************************/
/* print the sorted data set */
/*************************************/
proc print data=tempemp split='*';
id jobcode;
by jobcode;
var gender salary;
sum salary;
label jobcode='Job Code*========'
gender='Gender*======'
salary='Annual Salary*=============';
format salary dollar11.2;
where jobcode in ('PT1','PT2');
title 'Expenses Incurred for';
title2 'Salaries for Pilots';
run;


![【电子书】[职业技术] 《深入解析SAS:数据处理、分析优化与商业应用 (数据分析技术丛书)》[林建伟][epub+azw3] 【电子书】[职业技术] 《深入解析SAS:数据处理、分析优化与商业应用 (数据分析技术丛书)》[林建伟][epub+azw3]](https://www.04ip.com/template/qe/style/noimg/3.jpg)




