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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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