may you help me generate a set of 20 observations from standard normal distribution using do, do while and do until loops in SAS
Hi here are 3 basic programs to illustrate do, do while and do until loop.
hope this helps you to understand.
/*DO LOOP*/
data doloop;
age=5;
do year=2010 to 2030 by 1;
age=age+1;
output;
end;
run;
/*DO WHILE LOOP*/
data doloop;
age=5;
year=2010;
do
while(year<=2030);
year=year+1;
age=age+1 ;
output;
end;
run;
/*DO UNTIL LOOP*/
data doloop;
age=5;
year=2010;
do
until(year=2030);
year=year+1;
age=age+1 ;
output;
end;
run;
Thanks
Hi and welcome to the SAS Communities 🙂
First of all, please do not double post. You will get the help you need from a single post.
Regarding your question: When you say "observations", do you mean from a Standard Normal PDF or a random variate or something else? If it is the first, you can do like this (This is 21 obs though)
data Normal;
do x=-2 to 2 by .2;
y=pdf('Normal', x, 0, 1);
output;
end;
run;
Depending on what is meant, there is also the RAND function which produces random numbers from a normal distribution.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.