BookmarkSubscribeRSS Feed
sasprogramming
Quartz | Level 8

I would like to create a new column called 'Indicator' which is equal to "NOT_BLANK" if 'field' is not blank and "BLANK" if 'field' is blank.

How I would do this in excel is:

 

sasprogramming_0-1627433377422.png

How can I do this in SAS? Thanks.

 

Current data:

Field
A001_B001
A001
 
C002
C002_A001
 
B002

Desired data:

Field Indicator
A001_B001 NOTBLANK
A001 NOTBLANK
  BLANK
C002 NOTBLANK
C002_A001 NOTBLANK
   
B002 NOTBLANK
2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

INDICATOR = ifc(missing(FIELD),'BLANK','NOTBLANK');

Don't forget the set the length of INDICATOR or it will default to a length of 200.

 

ballardw
Super User

Can you describe how you will use that indicator?

 

You may not need a new variable. When value is based on a single variable often a simple format can be used to display desired text.

 

proc format;
value $blank
' '='BLANK'
other='NOTBLANK'
;
run;

Then use the format to display the existing character variable. Or use Newvar=put(var,$blank.); Formatted values can be used by most procedures though may need to explicitly allow use of missing values depending on procedure.

Similar can be done with numeric values and numeric format.

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
  • 2552 views
  • 2 likes
  • 3 in conversation