Hi All,
I want to know how many times a by group occured in a table and write that on a separate dataset (has to be a character number as I am concatenating with character as well). Can someone help please.
data have;
input Student_ID $ Course_ID $ Score;
cards;
M101 Eng 20
M101 Bio 20
M101 Eng 10
M101 Math 18
F103 Bio 18
F103 Math 99
F103 Eng 16
F103 Che 15
F103 Math 20
F103 Phy 17
RUN;
DATA want;
line='Totalcount'||Number of M101 by group occurance in have table||Number of F103 by group occurance in have table;
RUN;
Expected output:
line=Totalcount004006;
Probably many ways to skin this cat ...
data want;
length line $ 16;
retain line 'Totalcount';
count=0;
do until (last.Student_ID);
set have end=done;
by Student_ID;
count + 1;
end;
line = cats(line, put(count, z3.));
keep line;
if done;
run;
It's untested, but definitely headed in the right direction.
Are you sure you don't want to keep Student_ID as part of the output line?
That doesn't make sense, how would you parse the numbers back out.
Wouldn't you at least want a delimiter between the counts? Or a standard format, ie 8 digits?
Are you assuming the Z3 format, so no counts greater than 999?
What happens if you have more than two values for student_id such as M101 M102 M103 F101 F102 and F103?
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.