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?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.