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?
""Howard Schreier <hs AT dc-sug DOT org>"" <nospam@HOWLES.COM> wrote in
> 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.
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... */
length Var1 - Var3 8;
input Var1 - Var3;
1 234 2234
2 2451 346
2 364 63
3 641 563
1 32 9813
* get unique values of Var1 ;
proc sort data=test out=metadata nodupkey;
* create a SAS job from the data ;
filename temp catalog "work.temp.temp.source";
put "data _" Var1 +(-1) ";";
put " set test;";
put " where Var1=" Var1 +(-1) ";";
* check the job ;
proc fslist file=temp;
* looks good so submit it ;
%include temp / source;