BookmarkSubscribeRSS Feed
pacman94
Calcite | Level 5

I have the following dataset. if the value is blank I need the count variable to be  to be blank. Otherwise count all the comma + 1

Have

IDVALUE
ABC2
CDE 
EEA2,3
AWE4,5,6
DDE5
QWE 
WQE5,3,2

 

Have:

iDVALUEcount
ABC21
CDE  
EEA2,32
AWE4,5,63
DDE51
QWE  
WQE5,3,23

Here's what I have

if missing(VALUE) then count = .;

else count = countc(VALUE, ',')  + 1;

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Have you looked at function COUNTW ?

r_behata
Barite | Level 11
data have;
input ID $ VALUE $;
infile cards truncover;
cards;
ABC 2
CDE 
EEA 2,3
AWE 4,5,6
DDE 5
QWE 
WQE 5,3,2
;
run;


data want;
	set have;

	count=ifc(^ missing(VALUE),left(countw(VALUE,',')),'');
run;

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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