BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MikeTurner
Calcite | Level 5

I want to transpose the following data:

a b 1 x1 y1 x2 y2

c d 2 x3 y3 x4 y4;

Into:

a b 1 x1 y1

a b 1 x2 y2

c d 2 x3 y3

c d 2 x4 y4;

How to program?

Thanks!


1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

These data are in TXT file ?

data want;
infile datalines dlm=' ' truncover;
input a $ b $ c $ d $ e $ @;
do until( missing(d)); 
 output;
 input d $ e $ @; 
end;
input;
datalines;
a b 1 x1 y1 x2 y2
c d 2 x3 y3 x4 y4
;
run;

Ksharp

View solution in original post

6 REPLIES 6
Ksharp
Super User

These data are in TXT file ?

data want;
infile datalines dlm=' ' truncover;
input a $ b $ c $ d $ e $ @;
do until( missing(d)); 
 output;
 input d $ e $ @; 
end;
input;
datalines;
a b 1 x1 y1 x2 y2
c d 2 x3 y3 x4 y4
;
run;

Ksharp

MikeTurner
Calcite | Level 5

Thanks. But if the original data are in one datset, how to program it/

Ksharp
Super User

You have Five variables or Only one variable to hold a record?

MikeTurner
Calcite | Level 5

Thanks.

I have seven variables in my original dataset. Now I want to hold a record (5 variables) using the first 3 variables.

Ksharp
Super User

OK.

data have;
input (a1 - a7) (: $40.);
datalines;
a b 1 x1 y1 x2 y2
c d 2 x3 y3 x4 y4
;
run;
data want(drop=a4-a7);
 set have;
 x=a4;y=a5;output;
 x=a6;y=a7;output;
run;
  


Ksharp

Ksharp
Super User

If you have only one variable.




data have;
infile datalines length=len;
input a $varying200. len;
datalines;
a b 1 x1 y1 x2 y2
c d 2 x3 y3 x4 y4
;
run;
data want(keep=xx);
 set have;
 length x xx $ 400;
 i=4;
 x=catx(' ',scan(a,1),scan(a,2),scan(a,3));
 xx=catx(' ',x,scan(a,i),scan(a,i+1));
 do until(missing(scan(a,i)));
 output;
 i+2;
 xx=catx(' ',x,scan(a,i),scan(a,i+1));
 end;
run;

 

Ksharp

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1324 views
  • 0 likes
  • 2 in conversation