3. Array function
• Purpose:
when data has ordinary processed order,it will
be useful to use array to act as a temporary
storage base and this could largely reduce the
data; Only 9 lines
complexity of your code. input etc.
data; 27 lines array temperature_array {24}
input etc. temp1-temp24;
celsius_temp1 = 5/9(temp1 – array celsius_array {24}
32); celsius_temp1-
celsius_temp2 = 5/9(temp2 – celsius_temp24;
32); do i = 1 to 24;
... celsius_array{i} =
celsius_temp24 = 5/9(temperature_array{i} –
5/9(temp24 – 32); 32);
run; end;
run;
4. Example
data; 總共要27行
• 如果我們要將 24 input etc.
celsius_temp1 = 5/9(temp1 – 32);
個溫度變數從華 celsius_temp2 = 5/9(temp2 – 32);
24行
...
氏改成攝氏,最 celsius_temp24 = 5/9(temp24 – 32);
run;
直覺的程式寫法
是一個變數一個 data;
總共只要9行
變數慢慢地改 input etc.
array temperature_array {24} temp1-temp24;
array celsius_array {24} celsius_temp1-
celsius_temp24;
do i = 1 to 24;
celsius_array{i} = 5/9(temperature_array{i} – 32);
end;
run;
6. Exercise
• How to transfer 10 people’s weight and height
into BMI index BMI
身高 體重
?
1.5 50
1.6 60
1.7 70
1.6 60
1.7 70
1.8 80
1.5 55
1.6 65
1.7 75
1.7 73
7. • data bmi_calculate;
• array cal(10);
• do i=1 to 10;do end 的用法必定從do指令起頭(do end function need to start with do)
• Input h w @@;
• cal(i)=w/(h*h);
• bmi=cal(i);
• output;
• end;在do指令使用完後一定要以end結尾 如果要一行一
• cards; (do end function need to end with end) 行打的話 就要
• 1.5 50 手動keyin 10行
• 1.6 60 bmi的數值
• 1.7 70
• 1.6 60
• 1.7 70
• 1.8 80
• 1.5 55
• 1.6 65
• 1.7 75
• 1.7 73
• ;
• Proc print data=bmi_calculate;
• Var h w bmi;
• run;