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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.