BookmarkSubscribeRSS Feed
venkatard
Calcite | Level 5

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

6 REPLIES 6
DBailey
Lapis Lazuli | Level 10

not a function...but...

proc sql;

update ds1

set col1=null where col1=0;

quit;

venkatard
Calcite | Level 5

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

Amir
PROC Star

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.

Amir
PROC Star

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.

venkatard
Calcite | Level 5

I want to replace for all the variables.

esjackso
Quartz | Level 8

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

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
  • 1889 views
  • 0 likes
  • 4 in conversation