🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-10-2020 05:27 AM
(1100 views)
Hi
I am using proc transpose, how can I make it to put zeros where there is no observation for the variable.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much. You've helped me.