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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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