Hi
I am using proc transpose, how can I make it to put zeros where there is no observation for the variable.
data have;
input id value;
datalines;
1 2
1 .
1 3
3 4
5 6
7 8
2 .
3 .
5 0
9 .
;
proc sort data=have;
by id;
run;
proc transpose data=have out=have_2 (drop=_NAME_) prefix=value;
by id;
var value;
run;
proc stdize data=have_2 out=want reponly missing=0;
var _numeric_;
run;
Please post the code you are using and the data as data-step with datalines, so that we see what you have, then explain what you want/need.
Is this what you're looking for?
data have;
input id value;
datalines;
1 2
1 .
1 3
3 4
5 6
7 8
2 .
3 .
5 0
9 .
;
proc sort data=have;
by id;
run;
proc transpose data=have out=have_2 (drop=_NAME_) prefix=value;
by id;
var value;
run;
data want (drop=i);
set have_2;
array val [*] value:;
do i = 1 to dim(val);
if val[i] = . then val[i] = 0;
end;
run;
It's a bit unclear what you mean by "no observation" for the variable.
data have;
input id value;
datalines;
1 2
1 .
1 3
3 4
5 6
7 8
2 .
3 .
5 0
9 .
;
proc sort data=have;
by id;
run;
proc transpose data=have out=have_2 (drop=_NAME_) prefix=value;
by id;
var value;
run;
proc stdize data=have_2 out=want reponly missing=0;
var _numeric_;
run;
Thank you so much. You've helped me.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.