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:
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 |
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.