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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.