Date: Mon, 22 Dec 2008 17:35:13 +0530
Reply-To: Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Subject: Re: Splitting a large dataset
In-Reply-To: <d6a0d8f10812220359v43b1100eib3cbfa96420b2b62@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Oops... I never understood call execute correctly... however, the
slight disadvantage to the above is that there are multiple data steps
which are executed (one for each name), and it may be an efficiency
issue for large datasets.
OP, my solution will not work if your names contain spaces or special
characters... you need to modify it by using COMPRESS so that your
output dataset names contain only numbers, characters or underscores.
On Mon, Dec 22, 2008 at 5:29 PM, karma <dorjetarap@googlemail.com> wrote:
> Or call execute
>
> data test;
> input name $ data $;
> cards;
> Jens A
> Jens G
> Jens X
> Ole D
> Ole B
> ;run;
>
> data _null_;
> set test;
> by name;
> if first.name then
> call execute(catx(' ','data',name,
> '; set test;',
> 'where name =',quote(name),';'
> ,'run;'));
> run;
>
> 2008/12/22 Anindya Mozumdar <anindya.lugbang@gmail.com>:
>> A slightly more general solution to the one above -
>>
>> data test;
>> input name $ data $;
>> datalines;
>> Jens A
>> Jens G
>> Jens X
>> Ole D
>> Ole B
>> ;
>> run;
>>
>> proc sql noprint;
>> select distinct upcase(name) into :distnames separated by '|'
>> from test;
>> quit;
>> %let cntnames = %sysfunc(countc(&distnames, |));
>> %let cntnames = %eval(&cntnames + 1);
>> %put &cntnames &distnames;
>>
>> %macro splitDs();
>>
>> data %do i = 1 %to &cntnames; test_%scan(&distnames,&i, |) %end;;
>> set test;
>> %do i = 1 %to &cntnames;
>> %let currname = %scan(&distnames,&i, |);
>> if trim(upcase(name)) = "&currname"
>> then output test_%scan(&distnames,&i, |);
>> %end;
>> run;
>>
>> %mend splitDs;
>>
>> %splitDs()
>>
>
|