LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (October 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 25 Oct 2005 10:07:31 -0700
Reply-To:     Dale McLerran <stringplayer_2@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dale McLerran <stringplayer_2@YAHOO.COM>
Subject:      Re: How to randomly sample a number of variables from a full list
              of              all variables?
In-Reply-To:  <1115a2b00510250937o85b28ebid09d6c0ae64abc8a@mail.gmail.com>
Content-Type: text/plain; charset=iso-8859-1

--- Wensui Liu <liuwensui@GMAIL.COM> wrote:

> Dear Lister, > > Any idea how to draw a random sample from a full list of all > variables? > > Thank you so much! > > -- > WenSui Liu > (http://statcompute.blogspot.com) > Senior Decision Support Analyst > Cincinnati Children Hospital Medical Center >

WenSui,

Basically, you would want to construct a list of all variables and treat that list as a data set from which you want a sample. Draw your sample from the list and write the selected sample to a macro variable. The macro variable can be employed on a keep option of a set statement. Thus, the following code would construct a data set which has 30 variables randomly selected from the original input data set.

/* List all of the variables */ proc contents data=original noprint out=orig_contents(keep=name); run;

/* Select 30 variables at random from the list */ proc surveyselect in=orig_contents out=samp_contents method=srs sampsize=30 seed=1927894; run;

/* Write list of 30 variables to a macro variable */ proc sql noprint; select name into :varlist separated by " " from samp_contents; quit;

/* Construct data with only the 30 selected variables */ data random_vars; set original(keep=&varlist); run;

HTH,

Dale

--------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@NO_SPAMfhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 ---------------------------------------

__________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com


Back to: Top of message | Previous page | Main SAS-L page