BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

In my program, the  COUNTW function counts words as 1 when the values are missing. How to avoid. Please suggest. i am getting    dtf='M' when date is missing.

output needed

id   date                    dtf

1 2018-08-29            
2 2018-08                 D           
3 2018                      M
4

 

output getting

id   date                    dtf

1 2018-08-29            
2 2018-08                 D           
3 2018                      M
4                               M

data one;
input id date $10.;
datalines;
1 2018-08-29
2 2018-08
3 2018
4
;

data two;
set one;
dtf=choosec(countw(date, "-"),"M", "D", " ");
 aaa=countw(date, "-");
 run;
2 REPLIES 2
novinosrin
Tourmaline | Level 20

HI @knveraraju91  You can use the T modifier for countw to count missings as 0. 

 aaa=countw(date, "-",'t');
Tom
Super User Tom
Super User

You could just switch to using COUNTC() to count the number of hyphens.

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 16. 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
  • 693 views
  • 4 likes
  • 3 in conversation