sas20210423

data a;
set sashelp.class;
proc print;

data a1;
Array simple{3};/*simple1 simple2 simple3*/
proc print;

data a1;
Array simple{3} red green yellow;
proc print;

data a1;
Array simple{0:2} red green yellow;
proc print;

data a2;
input qa1-qa10 qb1-qb10;
array test{10} qa1-qa5 qb1-qb5;
put test{4}= test{6}= ;
cards;
1 1 1 6 1 1 1 1 1 1 8 2 2 2 2 2 2 2 2 2
;
proc print;

data new;
input qa1-qa10 qb1-qb10;
array test {10} qa1-qa5 qb1-qb5;
put test{4}= test{6}=;
cards;
1 1 1 6 1 1 1 1 1 1 8 2 2 2 2 2 2 2 2 2
;
run;


data a;
input x1 $:3. x2 $:3.;
array item(j) $12 x1-x10;
j=10;
put x1= x2= x3= item=;/*put输出在日志*/
cards;
aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj
;
run;

data test;
input s1-s5;
array s s1-s5;
do _i_=1 to 5;
s=s*100;
end;
cards;
.95 .88 .57 .90 .65
;
proc print;

/*隐含下标数组*/
data three;
input f1-f100;
array f f1-f100;
array c c1-c100;
do over f; /*等价于do _i_=1 to 100;*/
c=(f-32)*5/9;
end;
cards;
;
run;


data a;
set sashelp.class;
if age>14 then
do;
h_cm=30.5*height/12;
put name=age=h_cm=;
end;
proc print;
run;

do i=1 to 1000; /* 缺省的步长为1 */
do i=1 to n;
do i=n to 1 by -1; /* 起始值可以是变量;by:步长*/

do i=1,3,5,7;
do i=0.1 to 0.9 by 0.1, 1 to 10 by 1, 20 to 100 by 10;

do i=‘Saturday’, ‘Sunday’; /* 起始值可以是字符常数*/
do i=’01jan18’d, ’25feb18’d;
do i= ’01jan18’d to ’25feb18’d by 1;

data a;
do q=1 to 12;
output;
end;
proc print;
run;


/*数据在Excel里最多1048576条*/
data a;
do l=1 to 10;
do m=1 to 10;
do n=1 to 10;
do o=1 to 10;
do p=1 to 10;
do q=1 to 12;
output;
end;/*do q*/
end;/*do p*/
end;
end;
end;
end;
run;

data three;
set one(keep=number yyy);
select(yyy);
when(134,135,136,137,138,139,150,151,152,157,158,159,188) type="移动";
when(130,131,132,155,156) type="联通";
when(133,153,180,189) type="联通";
otherwise type=1; /*其他设置数值为1*/
end;
proc print data=three(keep=number type);
run;

data _null_;
do mon='jan', 'fab', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep';
select;
when (mon in('mar', 'apr', 'may')) put mon= 'spring';
when (mon in('jun', 'jul', 'aug')) put mon= 'summer';
therwise put mon= 'fall or winter';
end;
end;
run;

data one;
infile '/folders/myfolders/number.txt';
input number$:11. @@;
yyy=substr(number,1,3); /*从第一位取 取3位*/
xxxx=substr(number,4,4);
zzzz=substr(number,8,4);
proc print;

data one;
infile '/folders/myfolders/number.txt';
input number $1-11 yyy $1-3 xxxx $4-7 zzzz $8-11 @;
output;
input number $13-23 yyy $13-15 xxxx $16-19 zzzz $20-23 @;
output;
input number $25-35 yyy $25-27 xxxx $28-31 zzzz $32-35;
output;

data two;
set one(keep=number yyy);
if yyy>=134 and yyy<=139 or yyy=150 or yyy=151 or yyy=152 or yyy=157 or yyy=158 or yyy=159 or yyy=188 then type="移动";
if yyy=130 or yyy=131 or yyy=132 or yyy=155 or yyy="156" then type="联通";
if yyy=133 or yyy=153 or yyy=180 or yyy=189 then type="电信";
drop yyy;
proc print;

data four;
set one;
where xxxx="2321";/*一定要加双引号*/
where same and zzzz like "%5%";
proc print;

data four;
set one;
where xxxx="2321" and zzzz like "%5%";
proc print;

data test;
input Name$:10. Sex$ Score1 Score2 Score3 Score4 Score5 Score6;
avg=(Score1+Score2+Score3+Score4+Score5+Score6)/6;
format avg 6.2;
cards;
Zhangsan male 78 65 97 81 79 86
Lisi female 82 88 91 85 92 83
Wangwu male 77 69 75 56 60 72
zhongzhong male 86 79 85 82 78 80
;
proc print;


array day{7} d1-d7;
do i=1 to 7;
if day{i}=99 then day{i}=100;
end;

data five;
set test;
array score{6} Score1 Score2 Score3 Score4 Score5 Score6;
do i=1 to 6;
if score{i}>=90 then newavg=avg+1;
if score{i}<60 then newavg=avg-1;
end;
format newavg 6.2;
drop i;
proc print;

data five;
set test;
array score{6} Score1 Score2 Score3 Score4 Score5 Score6;
do i=1 to 6;
if score{i}>=90 then avg=avg+1;
if score{i}<60 then avg=avg-1;
end;
drop i;
proc print;

 

posted @ 2021-04-23 11:37  AnXiaoni  阅读(126)  评论(0)    收藏  举报