IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

Reply
Contributor
Posts: 63

IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

Super Contributor
Posts: 578

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

not a function...but...

proc sql;

update ds1

set col1=null where col1=0;

quit;

Contributor
Posts: 63

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

This will only replace for one variable. I need to replace for entire dataset

Super Contributor
Posts: 282

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

Hi,

Is this just for one column in a data set, if yes then a simple solution would be to use a data step including the following line of code:

if my_var=0 then my_var=.;

I did notice that you surrounded the zero value with quotes ("0"), so if it is a character variable then you could use:

if my_var="0" then my_var="";

Regards,

Amir.

Super Contributor
Posts: 282

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

Hi,

For a function you could conditionally use in a data step:

call missing(my_var);

and it wouldn't matter if the variable is numeric or character.

Regards,

Amir.

Message was edited by: Amir Malik - added data step reference.

Contributor
Posts: 63

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

I want to replace for all the variables.

Super Contributor
Posts: 333

Re: IS THERE ANY FUNCTION TO REPLACE VALUE "0" TO Missing for entire dataset

If there are multiple variables in the dataset that need to be converted you could combine post with an array:

data new;

     drop i j;

     set old;

     array c(*) _char_; /*or all your char variables that need to be converted*/

     array n(*) _numeric_; /*or all your numeric variables that need to be converted*/

     do i = 1 to hbound(c); /*sets the defined char vars where 0 to blank*/

          if c(i) = "0" then c(i) = "";

     end;

     do j = 1 to hbound(n); /*sets the defined numeric variables where 0 to missing*/

          if n(j)=0 then n(j)=.;

     end;

run;

Hope this helps!

EJ

Ask a Question
Discussion stats
  • 6 replies
  • 255 views
  • 0 likes
  • 4 in conversation