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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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