Saturday, March 22, 2014

SAS Basics Programming

1. Output a dataset
Proc Print data=datasetName;
run;

2. define dataset
data dataset;
input x y @@;
datalines;
1 2 2 2
;
run;

3. Array
data arry;
   array r[8] r1-r8;
   do i=1 to 8;
        r[i] = i*8;
   end;
run;

proc print data= arry;
run;

4. 代码缩进: TAB , Shift+ TAB

5. define vars:
data datasetName;
input x1-x5;
input Sales_X    Sales_Y    Sales_Z;
datalines;
1 2 3;
run;

Proc print data=dataSetName;
var Sales: /* 用前缀 省略 */
run;

6. Sum 如何用?其他类似functions怎么用? 如何输入输出
data setme;
/* input some data: can define some logic and have some var list */
x1=9;
x2=39;
x3=sum(of x1-x2);

x1=5; x2=6; x3=4; x4=9;
y1=34; y2=12; y3=74; y4=39;
result=sum(of x1-x4, of y1-y4);
/* end define logic */
/* start input data */
input x6-x8 @@;
datalines;
2 3 4 3 4 5
;
run;

proc print data=setme;
var x3 result x6-x8; /* define a print list */
run;


7.  sum用法, _ALL_, _NUMERIC_, _CHARACTER_ 用法:指所有此类变量
                data sales1;
                /* define any data manipulation step before the input statement , for example */
                myvar = 1;
                myvar2 = myvar + 1;
                /* start of input statement */
input sales_a  sales_b book @@ ;
datalines;
1 2 3 3 2 3
;
run;

data xyz;
set sales1;
sum_sales =  sum (of sales:) ;
sum_all_numeric = sum (of _NUMERIC_) ; /* sum all numeric data */
run;

proc print data=xyz;
var sales: sum_sales sum_all_numeric  /* sum_numeric; */ ;
run;

8. SAS调试技巧 -- 代码截断问题诊断

No comments:

Post a Comment