Generating Zeroes in PROC TRANSPOSE Output

From sasCommunity

Jump to: navigation, search

Example (from SAS-L):

proc plan seed=1788047502;
  factors
     id = 10 ordered
     sva = 5 of 10 random
     y = 1 of 100
     ;
  output out=work.plan;
  run;                                                     
proc transpose data=plan out=sva(drop=_:) prefix=sva; by id; var y; id sva; run;

The output is full of missing values. Suppose they ought to be zeroes.

Contents

[edit] Array Technique

data sva0;
set sva;
array ss[*] sva : ;
do j = 1 to dim(ss);
   if ss(j) = . then ss(j) = 0;
   end;
drop j;
run;

[edit] PROC STDIZE (SAS/STAT)

Suggested in the same SAS-L post:

proc stdize method=mean reponly missing=0 data=work.sva out=sva2;
  var sva:;
  run;

[edit] Updating a Frame of Zeroes

The strategy is to build an all-zero counterpart of the transposed data set, then use the UPDATE statement to overlay the non-missing values.

data work.frame / view=work.frame;
if 0 then set sva;
retain sva: 0;
set sva(keep=id);
run;                               
data work.zeros1; update work.frame work.sva; by id; run;

[edit] An Option in PROC TRANSPOSE?

An option to automatically do the replacement of missing values with zeroes would be welcome.

[edit] Format

This only affects the display of the values. It does not change what is stored.

proc format;
value zero . = '0';
run;
proc datasets nolist;
modify plan;
   format sva : zero.;
   run;
quit;

[edit] MISSING= Option

This too involves display only.

options missing='0';
Personal tools