BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RJ99
Calcite | Level 5

I have a small dataset ( ~2000 obs) and ~20 vars of which the var X is really crucial. Var x has values ( a and b ) such that a:b =6:4. I want to create two samples ( 1800 Obs and 200 obs) of this dataset such that in final datasets it keeps the ratio of a 😛 in var x same (6:4). How shall i do that.

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

Separate the original dataset into two, one for x=a and the other for x=b.

From x=a data set sample 1080 (60% of 1800) and 120 (60% of 200).  Do analogously for x=b data set.

Join the two subset to get the final file of 1800.  Ditto for 200.

When I do a sample without replacement, I will often add a variable to the data generated with ranuni (or one of the other random number generators in SAS), sort on that variable and then just do a DATA step to sequentially pull the samples.  You should also be able to do this with PROC SURVEYSELECT, but I like the simplicity in interpretation of the DATA step.

View solution in original post

4 REPLIES 4
RaviKommuri
Fluorite | Level 6

Can you please give some example of output datasets?

Doc_Duke
Rhodochrosite | Level 12

Separate the original dataset into two, one for x=a and the other for x=b.

From x=a data set sample 1080 (60% of 1800) and 120 (60% of 200).  Do analogously for x=b data set.

Join the two subset to get the final file of 1800.  Ditto for 200.

When I do a sample without replacement, I will often add a variable to the data generated with ranuni (or one of the other random number generators in SAS), sort on that variable and then just do a DATA step to sequentially pull the samples.  You should also be able to do this with PROC SURVEYSELECT, but I like the simplicity in interpretation of the DATA step.

Rick_SAS
SAS Super FREQ

For more details on Doc's advice, see the article   Sample without replacement in SAS - The DO Loop

RJ99
Calcite | Level 5

Thanks a lot Doc@Duke and Rick. It is really helpful.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1018 views
  • 3 likes
  • 4 in conversation