BookmarkSubscribeRSS Feed
BigD
Calcite | Level 5

Hi,

I have a very large dataset of clients with their ages and other attributes. Would it be possible to extract a set of records from this larger dataset such that the subset had a mean of say 55 years of age and a standard deviation of 2?

Thanks,

Bruce

4 REPLIES 4
ballardw
Super User

If I had to do this I would be tempted to use proc survey select with age as the stratum variable. Put different sizes for each strata (age) such that the result would have your desired mean and deviation with a total size that you want.

I see a certain amount of trial and error as even for a given total number of records there many ways to meet your requirement.

You might simplify code by restricting ages first to something like 45 to 65 to reduce the number of strata to use.

Hint if you use this method you probably should set a seed value so you can duplicate the data later if needed.

I would start with a trial data set of age and a weight variable and run them through  proc means to get an idea of the numbers I want as the strata counts for the data shape and range I want to use later.

Rick_SAS
SAS Super FREQ

I agree with @Ballardw. You can use the PDF function to determine what percentage to extract for each age stratum. For details and an example, see Construct normal data from summary statistics - The DO Loop

ballardw
Super User

After lunch and improved blood sugar I remembered we could generate a normal as specified. This will generate a data set to use with Proc SurveySelect as the SampSize option. Pick i in the do loop to match your desired size AND verify that the raw data set has at least as many persons with age for each as the _nsize_ values. This is intended to work with SRS sampling without replacement. Or you can generate sampling fractions.

data dist;
   do i = 1 to 5000;
      x = round((rand('NORMAL',55,2)),1);
      output;
   end;
   drop i;
run;

proc freq data=junk noprint;
   table x /  out=SampleSize (rename=(count=_nsize_) drop=percent);
run;

BigD
Calcite | Level 5

Thanks so much for these ideas and help. I will be trying them out!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2219 views
  • 3 likes
  • 3 in conversation