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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.