Using SAS EG v7.1
I have the following data where an event is represented by an ID and any number of codes (always strings) can be applied to each event.
data have;
input id$ code$ @@;
datalines;
aa x1 aa x1 aa x2
bb x1 bb y1 bb y1 bb z2 bb z4
cc x1 cc x2 cc y1 cc x1 cc x1 cc q1
dd z2 dd z2 dd z2 dd q1
;
run;
Episode IDs and Codes are always strings but can be of varying lengths.
The data below is what I want. Where the unique codes make up the column headings and the count is performed for each ID.
Does this work for you?
Do you need a table or report?
proc freq data=have;
table id*code / out=id_counts norow nocol nopercent sparse;
run;
proc transpose data=id_counts out=want (drop = _name_ _label_);
by id;
id code;
var count;
run;
@cobba wrote:
Using SAS EG v7.1
I have the following data where an event is represented by an ID and any number of codes (always strings) can be applied to each event.
data have; input id$ code$ @@; datalines; aa x1 aa x1 aa x2 bb x1 bb y1 bb y1 bb z2 bb z4 cc x1 cc x2 cc y1 cc x1 cc x1 cc q1 dd z2 dd z2 dd z2 dd q1 ; run;
Episode IDs and Codes are always strings but can be of varying lengths.
The data below is what I want. Where the unique codes make up the column headings and the count is performed for each ID.
Does this work for you?
Do you need a table or report?
proc freq data=have;
table id*code / out=id_counts norow nocol nopercent sparse;
run;
proc transpose data=id_counts out=want (drop = _name_ _label_);
by id;
id code;
var count;
run;
@cobba wrote:
Using SAS EG v7.1
I have the following data where an event is represented by an ID and any number of codes (always strings) can be applied to each event.
data have; input id$ code$ @@; datalines; aa x1 aa x1 aa x2 bb x1 bb y1 bb y1 bb z2 bb z4 cc x1 cc x2 cc y1 cc x1 cc x1 cc q1 dd z2 dd z2 dd z2 dd q1 ; run;
Episode IDs and Codes are always strings but can be of varying lengths.
The data below is what I want. Where the unique codes make up the column headings and the count is performed for each ID.
That is what I'm looking for. Thank you. How do I make the report a table?
It already does that, it's in the WANT data set. Change the name if you want it to have a different name.
@cobba wrote:
That is what I'm looking for. Thank you. How do I make the report a table?
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.