|
Hi,
Perhaps the following macro will work for your purposes. It assumes the
by-variable is character. If it is not, then you can change
if id = "&id" then output &dsn._&id;
To
if id = &id then output &dsn._&id;
%macro split_data
(dsn = /* name
of the input data set */
, id = /* a
data set will be created for every unique value of the
specified variable */
);
*create a macro variable containing a list of all the unique
by-variable values,
and a macro variable with the number of the items in the list;
proc sql noprint;
select distinct(&id)
into: &id_list
separated by ' '
from &dsn;
quit;
%let nobs = &sqlobs;
data
%do i = 1 %to &nobs;
%let id = %scan(&id_list, &i);
&dsn._&id
%end;
;
set &dsn;
%do i = 1 %to &nobs;
%let id = %scan(&id_list, &i);
if id = "&id" then output &dsn._&id;
%end;
run;
%mend split_data;
%split_data
(dsn = aa_trans
, id = trtgrp1
);
Scott Bucher
SAS Programmer
Office of Accountability
NYC Dept. of Education
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
SAS_learner
Sent: Monday, July 07, 2008 4:53 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Sample 26140: Creating a new data set for each BY-Group in
a data set
Hello data_null_ ,
Yes I would like to separate the big dataset that is coming out of
either Proc means (in my case after doing _type_ = 3) I want to cut
the main dataset into the number of datasets (by treatments ) and need
to merge them back to get into the table
thanks
On Mon, Jul 7, 2008 at 4:48 PM, data _null_, <datanull@gmail.com> wrote:
> Why do you think you need to do this? Unless you need to send the
> data to separate individuals or locations it is surely better to keep
> all the data together.
>
> On 7/7/08, SAS_learner <proccontents@gmail.com> wrote:
> > hello guys,
> >
> > Similar to Sample 26140 (http://support.sas.com/kb/26/140.html) in
my
> > dataset there can be n different treatments ( Numeric) and I want to
> > make them into different datasets.Some how It does not allowing me
> > to do, I
> am
> > not sure what I am doing wrong
> > This is when I changed the trtgrp1 to character (Which I do not
> > want to
> )
> > but still no luck
> >
> > Data aa_trans;
> > set aa_trans;
> > Trtgrp2 = trtgrp1*1 /*It was not converting straight away */ ;
> > Trtgrp3 = Trim(Left((Put(Input(Trtgrp2 ,best12.),$4.))) ; Run;
> >
> > %macro
> > break(byval);
> >
> > data &byval;
> > set aa_trans(where=(trtgrp3="&byval"));
> >
> > run;
> >
> > %mend;
> >
> > Proc Sort data = aa_trans ;;
> > By trtgrp1;
> > Run;
> > data _null_;
> > Set aa_trans ;
> > By trtgrp1 ;
> > if First.trtgrp1 then
> > Call Execute(%nrstr('%break(!!trim(trtgrp1)!!')'));
> > Run;
> > Quit;
> >
> > Even after changing it to character it is still not working any
Ideas ??
> > Thanks for the help
> >
>
|