array语句、do over语句、attrib语句、windo

2018-10-30  本文已影响0人  寒微123

array语句
(1)显示下标array语句:
形如:�ARRAY array-name {subscript} <> <<array-elements><(initial-values)>> �例 array simple{3} red green yellow; data; array x{3} a b c (1 2 3); file print; put x{1}= x{2}= x{3}=; run; � array x{5,3} score1-score15; data; array x{2,3} aa bb cc dd ee ff(1 2 3 4 5 6); file print; put x{2,1}=; run; � array c{3}等价于array c{3} c1-c3 �  array test{3} t1 t2 t3 (90 80 70) �数组中的变量必须全是数值型或字符串型 data; array x{2} aaa bbb('data' 'process');
file print;
put x{2}=;
run;
data;
规定数组中每一维的上下界:�array x{1:5,1:3} score1-score15;
array x{6:9,0:9} x60-x99;
file print;
put x{7,0};
run;
}表示SAS系统通过数组中变量的个数来确定下标。可用dim(数组名)函数计算数组元素个数。
data zz;
input d1-d7;
array day(
) d1-d7;
do i=1 to dim(day);
day(i)=day(i)+10;
end;
drop i;
cards;
99 11 22 222 22 3 44
1 2 3 4 5 6 7
;
run;
PROC PRINT;RUN;

(2)隐藏下标array语句
形如:ARRAY array-name <(index-variable)> <$> array-elements <(initial-values)>
如果没有规定下标变量,SAS系统使用自动变量i作为下标变量,下标变量范围从1到这个数组元素的个数
data test;
input sco1-sco5;
array s sco1-sco5;
do i =1 to 5;
s=s*100;
end;
cards;
0.95 0.88 0.57 0.90 0.65
1 2 3 4 5
;
run;
PROC PRINT;RUN;

do over语句
Do over 语句对每个数组元素自动地执行Do组中的语句,它等价于 do i=1 to k;�其中i是这个数组的下标变量,k是数组元素的个数。
Do over语句常用在对隐含下标数组元素执行Do组里的语句
data test;
input sc01-sc05;
array s sc01-sc05;
do over s;
s=s*100;
end;
cards;
0.95 0.88 0.57 0.90 0.65
1 2 3 4 5
;
PROC PRINT;
RUN;

attrib语句
在data步内允许用一个attrib语句来规定一个或几个变量的输出、输入格式,标签和长度,即规定变量属性
data a;
input x @@;
attrib x label='中国载人飞船'
length=8
informat=comma8.
format=dollar12.;
cards;
12,345,678
;
run;
proc print;
run;

window语句
创建用户专用的窗口,可用来显示文字说明或接受输入的数据
data null;
window start
#5 @26 'welcome to the sas system' color=yellow
#7 @19 'this program creates two sas data sets'
#8 @26 'and uses three procedures'
#12 @27 'press enter to continue';
display start;
stop;
run;

上一篇下一篇

猜你喜欢

热点阅读