I have a dataset that has the word NULL as a value and I am trying to replace it with a blank space but it doesn't work with the below IF statement. How can I overwrite/replace the word NULL?
IF TSA_CODE_1 = 'NULL' THEN TSA_CODE_1 = '';
Check if leading or trailing blanks are causing the issue.
IF strip(TSA_CODE_1) = 'NULL' THEN TSA_CODE_1 = '';
Hi,
That should work, unless your variable TSA_CODE_1 isn't what it appears to be from this code.
Here's an example, note how a & c are both strings, whereas b is a numeric.
Reduce your code down to run a similar test and check the log for NOTES/WARNINGS & ERRORS
data t ;
a='NULL' ;
b=. ;
c='NULL' ;
if c='NULL' then
c='' ;
run ;
proc print data=t ;
run ;
That worked to remove the NULL values and the 6 digit code string that is also in the column. I want to maintain the code string but just remove any instances of the word NULL in the same field. How can I do this?
| TSA_CODE_1 |
| NULL |
| 061002 |
| 071004 |
| 101002 |
| NULL |
| NULL |
I prefer call missing instead of ' ' or .
data t ;
a='NULL' ;
b=. ;
c='NULL' ;
run ;
data want;
set t;
if c='NULL' then call missing(c) ;
run;
Check if leading or trailing blanks are causing the issue.
IF strip(TSA_CODE_1) = 'NULL' THEN TSA_CODE_1 = '';
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 save with the early bird rate—just $795!
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.