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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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