SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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