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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 617 views
  • 0 likes
  • 3 in conversation