hi masters,
i am having one dataset it has some data i want to transpose it by using only arrays.
data sbp;
input subject $ visit sbp;
datalines;
101 1 160
101 3 140
101 4 130
101 5 120
202 1 141
202 3 161
202 4 171
202 5 181
;
run;
Maxim 14: use the right tool. No arrays are needed, SAS has a procedure for this (Maxim 7):
proc transpose data=sbp out=want (drop=_name_) prefix=sbp;
by subject;
id visit;
var sbp;
run;
why not proc transpose as @Kurt_Bremser neatly puts. Any particular reason like learning?
Is there any reason that you have to use data step ?
data sbp;
input subject $ visit sbp;
datalines;
101 1 160
101 3 140
101 4 130
101 5 120
202 1 141
202 3 161
202 4 171
202 5 181
;
run;
proc sql noprint;
select max(visit) into : n separated by ' ' from sbp;
quit;
data want;
set sbp;
array x{*} visit1-visit&n;
retain visit:;
by subject;
x{visit}=sbp;
if last.subject;
drop visit sbp;
run;
@ravindra2 wrote:
hi masters,
i am having one dataset it has some data i want to transpose it by using only arrays.
data sbp; input subject $ visit sbp; datalines; 101 1 160 101 3 140 101 4 130 101 5 120 202 1 141 202 3 161 202 4 171 202 5 181 ; run;
1) why force data step and
2) What specific result should your transpose look like?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.