BookmarkSubscribeRSS Feed
ravindra2
Fluorite | Level 6

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;
4 REPLIES 4
Kurt_Bremser
Super User

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;

 

novinosrin
Tourmaline | Level 20

why not proc transpose as @Kurt_Bremser neatly puts. Any particular reason like learning?

Ksharp
Super User

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

@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?

SAS Innovate 2025: Register Now

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!

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
  • 1073 views
  • 2 likes
  • 5 in conversation