IS THERE ANY FUNCTION TO REPLACE null TO empty string

Reply
Frequent Contributor
Posts: 90

IS THERE ANY FUNCTION TO REPLACE null TO empty string

I have used coalescec function

(coalescec(Name,' ' )) for this.But it is not working.KIndly help me on this.

Super User
Posts: 9,681

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

How about:

if name = 'Null' then name=' ';

Frequent Contributor
Posts: 90

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

In the Expression column I have given this.

I cannot validate this expression.Its throwing error.

I am using SAS DI studio 4.21.

Super User
Posts: 9,681

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

OK. Try this:

ifc(name='null',' ',name)

Super User
Super User
Posts: 6,500

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

What do you mean?

In SAS character variables are stored as fixed length and are padded on the right with spaces.  I am not sure there is any difference between the terms "null" and "empty string".

Contributor
Posts: 20

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

try function

tranwrd (name, "null" , " " )

Occasional Contributor
Posts: 12

Re: IS THERE ANY FUNCTION TO REPLACE null TO empty string

I will present this and other things at NESUG this year

the following macro converts all nulls to zeros (that is what I needed) for eitehr a set of variables or for all numeric ones

you can easilly modify it to convert string 'null' to '' (blank) without typing multiple lines of code, even if here was a function this is better as you do not need to write 100 of lines to process 100's of variables

I attached a small  text file, for some reason I could nto paste code from my sas editor

Attachment
Ask a Question
Discussion stats
  • 6 replies
  • 1646 views
  • 0 likes
  • 5 in conversation