BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ZaneleD
Calcite | Level 5

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
Ksharp
Super User
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;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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.

maguiremq
SAS Super FREQ

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. 

Ksharp
Super User
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;
ZaneleD
Calcite | Level 5

Thank you so much. You've helped me.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 603 views
  • 0 likes
  • 4 in conversation