turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Simulate normal data for HLM

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-28-2016 11:41 AM

I'm new to SAS and I have never simulated data before. For a project that I am currently working on, I'd like to simulate a normal and non-normal dataset for analysis with a simple hierarchical linear model. I would like to be able to compare the true parameters of the simulated datasets with the parameter estimates I calculate through analysis. I have read a lot of answers on this website and on others, but I still do not know how to proceed. Can anyone please point me in the right direction, or perhaps give me an example? I have no code to share because I do not know how to write it for the problem that I am trying to solve.

Thank you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-28-2016 03:40 PM

To compute a normal random variable you can use the following:

data sim;

do i=0 to <N>;

NormalVar = &Mean + &STD*rannor(<seed>);

output;

end;

run;

Replace <N> with the number of cases you desire and <seed> with some number for reproducibility of your results. You can assign any values you please to macro variables &Mean and &STD. Both of them are optional and, if you don't use them, your random variable will have mean=0 and STD=1.

You can then take a log, exponentiate or do some other transformation to make your normal variable be not normal.

data sim;

do i=0 to <N>;

NormalVar = &Mean + &STD*rannor(<seed>);

output;

end;

run;

Replace <N> with the number of cases you desire and <seed> with some number for reproducibility of your results. You can assign any values you please to macro variables &Mean and &STD. Both of them are optional and, if you don't use them, your random variable will have mean=0 and STD=1.

You can then take a log, exponentiate or do some other transformation to make your normal variable be not normal.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-28-2016 11:46 PM

Post it at IML forum, since it is about data simulation. Rick is there.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-30-2016 08:59 AM

If you have never simulated data before, you might start by reading the paper "Ten tips for simulating data with SAS."