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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 746 views
  • 0 likes
  • 4 in conversation