DATA Step, Macro, Functions and more

Convert Zeros to NULL

Reply
Occasional Contributor
Posts: 8

Convert Zeros to NULL

Hello,

   I have a very large dataset with multiple variables. Some of these variables have a value of zero, which I'd like to convert to 'NULL'. How would I go about doing this? 


Eg:

Desciprtion, VariableA#, VariableB#.......VariableZ#

 

 

Thanks! 

Super User
Posts: 9,549

Re: Convert Zeros to NULL

Posted in reply to JayCompany

In SAS, missing numerical values are represented by a dot. So do

if variable = 0 then variable = .;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 12,996

Re: Convert Zeros to NULL

[ Edited ]
Posted in reply to JayCompany

One way assuming all the variables are numeric:

data want;
   set have;
   array v var1 var2 varx;   /* add variables as needed*/
   do i=1 to dim(v);
     if v[i]=0 then v[i]=.;
   end;
   drop i;
run;

 

 

Super Contributor
Posts: 448

Re: Convert Zeros to NULL

Posted in reply to JayCompany

If the variables are numeric then try this:

 

PROC FORMAT;
value Null .="NULL";
run;
data want;
set Have ;

array Change _numeric_;
do over change;
if change>10 then change=.;
end;
FORMAT _NUMERIC_ Null.;
run;

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 3 replies
  • 143 views
  • 0 likes
  • 4 in conversation