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 = '';
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.