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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.