Suppose I have a data set with three groups Abc,Def,Ghi Something like this:
Group X_var
A 3
A 5
A 2
B 1
B 12
B 6
B 78
C 99
C 4
The x variable doesn't really matter. I want to be able to write to the LOG "Name of Group1: Abc (n=3)" "Name of Group2: Def (n=4)" "Name of Group3: Ghi (n=2)".
Is there a way that I can automatically extract the different group names and their sample size (perhaps with a function)?? I should add that this will be part of a larger macro so it needs to be "macro-friendly".
Not sure if this is you are after, also not sure what is "macro-friendly", all I know there is hardly any SAS code can NOT be wrapped up using macro.
data have;
input Group$ X_var;
cards;
A 3
A 5
A 2
B 1
B 12
B 6
B 78
C 99
C 4
;
data _null_;
do i=1 by 1 until (last.group);
set have;
by group notsorted;
end;
put "Name of Group" _n_ ":" group "(n=" i ")";
run;
Haikuo
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.