m*********7 发帖数: 343 | 1 I have a data set now including two variables, one is the results of an
experiment and another one is the group number. And I want to separate the data set into several small data sets with only one certain group number and results in that group. For example, if there are 8 observations with group number 1 or 2 or 3, and create three data sets; if with group number 1 or 2, and create two data sets; if with group number 1 to n, and create n data sets.
Can I use a loop to the number of max(group) | l*******n 发帖数: 13 | 2 try
%macro xxx(g);
proc sql;
create table table&g as
select a,b from tablename where a=&g;
run;quit;
%mend; | m*********7 发帖数: 343 | 3 Thanks for the replying. I tried this one, but it seems like creating one
table each time. Can I use something to create n table at one time, like a
loop function? | q**j 发帖数: 10612 | 4 you are greedy, but greed is good :)
1. get unique group numbers into a table.
proc sort data = yourdata out=group(keep=group) nodupkey;
by group;
run;
2 do a lot of preparation.
data _NULL_;
set group end=lastobs;
name = cats("group",group);
call symput(cats("group",_n_),name);
if _n_ = 1 then
do;
longname= name;
longgroupvalue= '"'||cats(group)||'"';
end;
else
do;
longname=cats(longname)|| " "||cats(name);
longgroupvalue = cats(longgroupvalue)||", "||'"'||cats(group)||'"';
end;
if lastobs then | m*********7 发帖数: 343 | 5 Wa~~ So detailed explanation! Thanks a lot! Seems complicated for me. I
guess I'll need sometime to go through it little by little later. | o****o 发帖数: 8077 | 6 here is a more general fast solution:
data have ;
input mth: yymmn6. a b c ;
cards ;
200801 1 2 3
200802 1 2 3
200802 4 5 6
200803 1 2 3
200803 4 5 6
200803 7 8 9
;
run ;
/* intentionally to disorder */
proc sort data=have; by c; run;
/* Apply the Hash List approach credited to Richard A. DeVenezia */
data _null_;
if _n_=1 then do;
declare hash h0(ordered:'YES');
h0.defineKey('mth');
h0.defineData('mth', 'a', 'b', 'c', 'h');
h0.defineDone();
【在 m*********7 的大作中提到】 : I have a data set now including two variables, one is the results of an : experiment and another one is the group number. And I want to separate the data set into several small data sets with only one certain group number and results in that group. For example, if there are 8 observations with group number 1 or 2 or 3, and create three data sets; if with group number 1 or 2, and create two data sets; if with group number 1 to n, and create n data sets. : Can I use a loop to the number of max(group)
|
|