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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.