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;
This will only replace for one variable. I need to replace 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.
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.
I want to replace for all the variables.
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
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.
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.