DATA Step, Macro, Functions and more

Replacing zeros with missing values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

Replacing zeros with missing values

I know the following code works well, but does anyone have alternative suggestions to write a more efficient code that replaces zeros with missing values? 


Here is a sample dataset: 

data work.sample;
 infile cards expandtabs truncover;
input 	ID	shrout	shrout1	shrout2;
cards;
26232409	0	2	50997000
26232409	0	3	50997000
26232409	53598	0	50997000
10623630	10097	2	0
5856168			.		.	.
;
run;

Here is the code:

data work.sample;
	modify work.sample;
	array vars{*} shrout shrout1 shrout2; 
	do i = 1 to dim(vars);
        if vars{i}=0 then call missing(vars{i});
	end;
run;

 


Accepted Solutions
Solution
‎06-01-2017 08:26 PM
Super User
Posts: 17,818

Re: Replacing zeros with missing values

This was actually asked yesterday on here, see latest posts. You only need the last part, PROC STDIZE 

 

https://communities.sas.com/t5/Base-SAS-Programming/Back-fill-empty-rows-with-zero-values/m-p/363458...

View solution in original post


All Replies
Solution
‎06-01-2017 08:26 PM
Super User
Posts: 17,818

Re: Replacing zeros with missing values

This was actually asked yesterday on here, see latest posts. You only need the last part, PROC STDIZE 

 

https://communities.sas.com/t5/Base-SAS-Programming/Back-fill-empty-rows-with-zero-values/m-p/363458...

Frequent Contributor
Posts: 110

Re: Replacing zeros with missing values

Perfect, thanks for pointing that out, @Reeza

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 102 views
  • 1 like
  • 2 in conversation