BookmarkSubscribeRSS Feed
edomachowske
Calcite | Level 5

Hello!

 

I need to get frequencies for a number of different symptoms experienced by patients in a data set. The problem is that they are all listed under the same variable: Symptoms and each column under it has a different string of letters depending on what the patient presented with.

 

Symptoms

C

C, A

W, A

C, W, A

W, R, V

 

I have been able to count the single letters but not all of the "C"'s "W"'s etc. 

 

Is there an easy way to do this?

 

Thanks!

3 REPLIES 3
art297
Opal | Level 21

Here is one way:

 

data have;
  informat Symptoms $50.;
  input Symptoms &;
  cards;
C
C, A
W, A
C, W, A
W, R, V
;

data need;
  set have;
  _n_=1;
  do while (scan(Symptoms,_n_,',') ne '');
    symptom=scan(Symptoms,_n_,',');
    output;
    _n_+1;
  end;
run;

proc freq data=need;
  tables symptom;
run;

HTH,

Art, CEO, AnalystFinder.com

 

mkeintz
PROC Star

You need to loop over each individual symptom in symptons.  Output each of the individuals, and then run proc freq:

 

 

data have;
  input symptoms $8.;
datalines;
C
C, A
W, A
C, W, A
W, R, V
run;

data vhave/ view=vhave;
  set have;
  length symptom $1.;
  do I=1 to countw(symptoms,',');
    symptom= left(scan(symptoms,I,','));
	output;
  end;
run;
proc freq data=vhave;
  tables symptom;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User

Better post the output you need too .

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 736 views
  • 0 likes
  • 4 in conversation