LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 11 Dec 2005 15:30:02 +1100
Reply-To:     Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU>
Subject:      Re: How to create new data set for each value of a variable?
Comments: To: sas-l@uga.edu

""Howard Schreier <hs AT dc-sug DOT org>"" <nospam@HOWLES.COM> wrote in message news:200512110245.jBB0pndJ001749@mailgw.cc.uga.edu... > On Fri, 9 Dec 2005 13:13:04 -0800, eric.pashman@GMAIL.COM wrote:

munch of good stuff from Howard...

>>You are heading in a direction which will make everything more difficult >>than it has to be. >> >>Better to do the partitioning on the fly when the exporting is done. >>Details will depend on the type of export file (Excel, text, other) and >>possibly on the version of SAS in use and the products licensed. >> >>On Fri, 9 Dec 2005 12:35:37 -0800, eric.pashman@GMAIL.COM wrote: >> >>>I have a data set that I want to chop up into multiple smaller datasets >>>based on the value of one or more of the variables in the set. That >>>is, I want to create a bunch of new datasets, each one containing only >>>the observations that share a value of a certain variable or group of >>>variables. (Reason: I'm eventually exporting each data set to a >>>different output file.) >>> >>>So if the data looks like >>> >>>Var1 Var2 Var3 >>>1 234 2234 >>>2 2451 346 >>>2 364 63 >>>3 641 563 >>>1 32 9813 >>> >>>then, for example, I'd want to create three new data sets, one that >>>contains all the records who's value of Var1 = 1, another who's value >>>of Var = 2, and a third who's value of Var = 3. >>> >>>The problem, of course, is that there are too many different values of, >>>e.g., Var1 to just use subsetting IF statements or something similar. >>>Any pointers? >>> >>>Thanks, >>> >>>Eric

Ignoring the sage advice of Howard, and merely addressing the problem as stated, this approach might meet your needs (there are a number of other approaches, such as macro, call execute, etc). I've only addressed "...share a value of a certain variable" and not "...or group of variables":

/* oh how i wish folks would post a working example of test data so i didn't have to create the data step myself... */ data test; length Var1 - Var3 8; input Var1 - Var3; datalines; 1 234 2234 2 2451 346 2 364 63 3 641 563 1 32 9813 ; run;

* get unique values of Var1 ; proc sort data=test out=metadata nodupkey; by Var1; run;

* create a SAS job from the data ; filename temp catalog "work.temp.temp.source"; data _null_; set metadata; file temp; put "data _" Var1 +(-1) ";"; put " set test;"; put " where Var1=" Var1 +(-1) ";"; put "run;"; run;

* check the job ; proc fslist file=temp; run;

* looks good so submit it ; %include temp / source; filename temp;


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