BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
emaguin
Quartz | Level 8

Hi,

I want to generate a data set. What i want to learn is the SAS commands to do this; the specifics i describe are not the focus per se. I want to add that i know how to do this in spss and there, as is true here, the issue is the commands.

That said. Let's say i want to create 20000 records with each record having four variables: record number (_N_ ??), x1, a draw from a normal distribution with a mean of 3 and an SD of 2; x2, a draw from a uniform distribution with a range of 2 to 5 and y, the resulting value of this regression equation y = 3.0 + 2.0*x1 + 4.0*x2+err

where err equals a draw from a normal distribution with a mean of 0 and an SD of 1.5.

I expect that this is a trivially simple thing to do; i need to know the commands and how those commands are located in a data xxx1; set ??used??; run; code block.

Thanks, Gene Maguin

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    do record_number=1 to 20000;
        x1=rand('normal',3,2);
        ...
        output;
    end;
run;

 

I leave the code to calculate X2 and Y to you as a homework assignment. Please see the RAND() function documentation for other random number generation options. 

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
data want;
    do record_number=1 to 20000;
        x1=rand('normal',3,2);
        ...
        output;
    end;
run;

 

I leave the code to calculate X2 and Y to you as a homework assignment. Please see the RAND() function documentation for other random number generation options. 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 985 views
  • 0 likes
  • 2 in conversation