02-17-2017 01:38 PM
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.
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?
02-17-2017 02:06 PM
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;
Art, CEO, AnalystFinder.com
02-17-2017 02:07 PM
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;