BookmarkSubscribeRSS Feed
Sean_OConnor
Fluorite | Level 6

Folks,

 

I wonder could anyone provide some guidance for the following query, please?

 

I have a dataset for 10,000 households on income. 

 

I would like to see the impact of an increase in income of ranging between 500-1000 for a random 200 households can have on headline figures such as the percentage of the sample at risk of poverty. 

 

Would anyone know how the best way to write a command to increase a variable between 500-1000 for a random 200 observations?

 

Any help would be most welcome.

 

Kind regards,

 

Sean 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, you can use the random number generator:

https://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas.html

Something like:

data A;
call streaminit(123);       /* set random number seed */
do i = 1 to 200;
   u = rand("Uniform") * 10000;     
   output;
end;
run;

This would give you 200 random observation numbers.  Merge this to your data based on u=_nobs_ (will need an actual variable), then apply an if - note that this is just pseudocode, I haven't time to test anything right now:

data want;
  merge have (in=a) a (in=b);
by u;
if b then do;
/* set addition here */
end;
run;

 

 

Astounding
PROC Star

This can be done in 1 step, but the statistical theory proving that this is in fact a random selection is complex.

 

data want;

set have nobs=denominator;

retain numerator 200;

if ranuni(12345) < numerator / denominator then do;

   value = value + 500;  /* how do you know how much to add?? */

   numerator = numerator - 1;

end;

denominator = denominator - 1;

run;

TomKari
Onyx | Level 15

Rick Wicklin discusses using random number generators in a number of places. Here's an SGF paper that discusses the topic.

 

Tom

 

https://www.lexjansen.com/scsug/2016/SAS-Ten-Tips.pdf

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 709 views
  • 1 like
  • 4 in conversation