Help using Base SAS procedures

create random dataset

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

create random dataset

I'm trying to create a random dataset with 1000 observations and 3 variables(Employee_id, sex, age). I want the employee_id to be in the range (5213 to 9899), sex (as male,female or unknown) and age in between 25 to 75. Is there any function/sas proc thru which i can achieve this? I want the employee id to be random rather than consecutive.Thanks for help


Accepted Solutions
Solution
‎01-11-2013 09:15 PM
Respected Advisor
Posts: 4,919

Re: create random dataset

A simple way :

 

proc format;
value sexFmt
     1 = "male"
     2 = "female"
     3 = "unknown";
run;

data test;
format sex sexFmt.;
call streaminit(6875687);
do empId = 5213 to 9899;
     sex = rand("TABLE",0.4,0.4);
     age = 25 + floor(51*rand("UNIFORM"));
     output;
     end;
run;

proc surveyselect data=test out=want n=1000 noprint; run;

PG

PG

View solution in original post


All Replies
Solution
‎01-11-2013 09:15 PM
Respected Advisor
Posts: 4,919

Re: create random dataset

A simple way :

 

proc format;
value sexFmt
     1 = "male"
     2 = "female"
     3 = "unknown";
run;

data test;
format sex sexFmt.;
call streaminit(6875687);
do empId = 5213 to 9899;
     sex = rand("TABLE",0.4,0.4);
     age = 25 + floor(51*rand("UNIFORM"));
     output;
     end;
run;

proc surveyselect data=test out=want n=1000 noprint; run;

PG

PG
Contributor
Posts: 22

Re: create random dataset

PGSTATS - Thanks a lot. I learned something new about the streaminit and rand table option.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 244 views
  • 0 likes
  • 2 in conversation