BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Have a look at the COUNT function.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

count words site:sas.com
art297
Opal | Level 21
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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1178 views
  • 0 likes
  • 3 in conversation