Basically, to use Standard deviation function (STD), I know that I can use it as STD = STD(Var1, Var2, Var3);
but how about if I have 100 numerical variables?
In input statement, I know that it is possible to use like this, input Var1 - Var100;
Then, for STD function, do I have to write all 100 variables into parenthesis?
Hi @skjhzzang
You can use an array to do that. You can then refer to the array name e.g. myarray(*) in a function like below:
data STD std2;
input Name : $5. Var1 Var2 Var3;
array myarray (*) Var1 - Var3; /* Reference you variables once */
do i=1 to dim(myarray);
Mean=Mean(of myarray(*));
std=round(std(of myarray(*)), 0.01);
end;
drop i;
output std;
if std<=150 then
output std2;
datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;
run;
Hi @skjhzzang
You can use an array to do that. You can then refer to the array name e.g. myarray(*) in a function like below:
data STD std2;
input Name : $5. Var1 Var2 Var3;
array myarray (*) Var1 - Var3; /* Reference you variables once */
do i=1 to dim(myarray);
Mean=Mean(of myarray(*));
std=round(std(of myarray(*)), 0.01);
end;
drop i;
output std;
if std<=150 then
output std2;
datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;
run;
stdev=std(of var1-var100);
If they all have the same prefix, you do not even need the array:
result = std(of var:);
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.