BookmarkSubscribeRSS Feed
5imon
Calcite | Level 5

I have a dataset that includes multiple diagnosis codes in one ";" delimited variable sorted by patient and year.

 

For example.

 

Patient  Year      Codes

1             18         0123;4444;2346;0912

2.           17          1234;4444

3            17          0912

4            16          0123;2346;0912

5            15          4444

 

I would like to know the frequency of the individual codes grouped by year without having to manually enter all of the codes. 

 

Example output

             2015   2016   2017   2018     Total

0123       n         n         n          n           n

4444

2346

0912

 

I have tried with proc freq but it will not look within the strings. Proc tabulate will work but only if I manually enter each code. 

 

Any help with a more efficient way of doing this?

 

Any help would be appreciated.

 

Simon

3 REPLIES 3
novinosrin
Tourmaline | Level 20

transpose using scan of codes one by one

proc summary/freq  using yearcodes

then transpose again 

Ksharp
Super User
data have;
input Patient  Year      Codes $40.;
cards4;
1             18         0123;4444;2346;0912
2         17          1234;4444
3            17          0912
4            16          0123;2346;0912
5            15          4444
;;;;
run;

data temp;
 set have;
 do i=1 to countw(Codes,';');
   code=scan(Codes,i,';');output;
 end;
run;

proc tabulate data=temp;
class year code;
table code=' ',year=' '*n all='Total';
keylabel n=' ';
run;
Astounding
PROC Star

Also note, the form in which you have stored your data is relatively useless.  Take a good look at the form that comes out of @Ksharp's DATA step.  That would be much more flexible for both calculating and reporting.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 751 views
  • 2 likes
  • 4 in conversation