BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AP101
Obsidian | Level 7

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Check if leading or trailing blanks are causing the issue.

 

IF strip(TSA_CODE_1) = 'NULL' THEN TSA_CODE_1 = '';

Thanks,
Suryakiran

View solution in original post

6 REPLIES 6
AMSAS
SAS Super FREQ

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 ;
AP101
Obsidian | Level 7

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
novinosrin
Tourmaline | Level 20

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;
Vibcom
Fluorite | Level 6
As we all know ,Null is a char value. So you can remove it using either if condition or with call missing--
1. data test;
input x1 $;
if X1='null' then x1='';
cards;
A1
null
A2
;
run;

2. data test;
input x1 $;
if X1='null' then call missing(x1);
cards;
A1
null
A2
;
run;
SuryaKiran
Meteorite | Level 14

Check if leading or trailing blanks are causing the issue.

 

IF strip(TSA_CODE_1) = 'NULL' THEN TSA_CODE_1 = '';

Thanks,
Suryakiran
AP101
Obsidian | Level 7
Thanks! Adding the STRIP worked. I now have: 



TSA_CODE_1
 
061002
071004
101002
 
 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 6 replies
  • 2183 views
  • 6 likes
  • 5 in conversation