Help using Base SAS procedures

Counting symbol or split field?

Reply
N/A
Posts: 0

Counting symbol or split field?

I am trying to get a count of comorbidities for each patient. I have a variable that is a list of comorbidities seperated by commas. Is there a way to count the commas in the field? Or would you advise splitting them into multiple variables? The most anyone has is 11 comorbidities.

Sample:
Sleep apnea,Lichen planus,IBS,RAD,Multinodular thyroid,Actinic keratosis,Neuropathy
Super Contributor
Super Contributor
Posts: 3,174

Re: Counting symbol or split field?

Posted in reply to deleted_user
Have a look at the COUNT function.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

count words site:sas.com
PROC Star
Posts: 7,467

Re: Counting symbol or split field?

Posted in reply to deleted_user
Vanessa,

If there is a chance that some records don't have any comorbidities, you could do something like the following:

data have;
informat comorbidities $255.;
infile cards truncover;
input comorbidities &;
i=1;
count=0;
do while (not(missing(scan(comorbidities,i,','))));
i+1;
count+1;
end;
cards;
Sleep apnea,Lichen planus,IBS,RAD,Multinodular thyroid,Actinic keratosis,Neuropathy
Sleep apnea,Lichen planus,IBS

test
;

HTH,
Art
Ask a Question
Discussion stats
  • 2 replies
  • 106 views
  • 0 likes
  • 3 in conversation