BookmarkSubscribeRSS Feed
OWINO
Calcite | Level 5

may you help me generate a set of 20 observations from standard normal distribution using do, do while and do until loops in SAS

3 REPLIES 3
Shivam
Calcite | Level 5

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

PeterClemmensen
Tourmaline | Level 20

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;
PaigeMiller
Diamond | Level 26

Depending on what is meant, there is also the RAND function which produces random numbers from a normal distribution.

 

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=lefunctionsref&docsetTarget=p...

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1245 views
  • 0 likes
  • 4 in conversation