BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Daily1
Quartz | Level 8

hi,

I have 4 character columns in a table, and am tring to combine the 2 columns into new column, like append with two columns.

data have;
  infile datalines truncover dlm=',' dsd;
  input catX $ catY $ value $ ALFA $;
  datalines;
X1,Y1,2,A
X1,Y1,4,D
X1,Y2,1,G
X1,Y2,3,H
X2,Y1,2,K
X2,Y2,2,H
X2,Y2,3,Y
X2,Y2,3,G
;

proc report data=have nowd out=temp;
  column  catY catX value  ALFA; 
define  catY/group noprint;
define catX / 'A' group;
define ALFA / 'B' ;
 Compute before catY;
Line @1 catY $50.;
endcomp; 
run;

First is output on my query and second table i want .

Daily1_0-1663243954906.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
  infile datalines truncover dlm=',' dsd;
  input catX $ catY $ value $ ALFA $;
  datalines;
X1,Y1,2,A
X1,Y1,4,D
X1,Y2,1,G
X1,Y2,3,H
X2,Y1,2,K
X2,Y2,2,H
X2,Y2,3,Y
X2,Y2,3,G
X1,Y3,2,A
X1,Y3,4,D
X1,Y4,2,A
X1,Y4,4,D
X2,Y4,2,A
X2,Y4,4,D
;
ods excel file='c:\temp\want.xlsx';
proc report data=have nowd style={cellwidth=2cm};
  column  catY catX value  ALFA; 
define  catY/order noprint;
define catX /  order noprint;
define value/display 'A' style={just=r};
define ALFA / 'B' ;
Compute before catX/style={just=l};
Line  catX $50.;
endcomp;
Compute before catY/style={just=l};
Line  catY $50. ;
endcomp; 
run;
ods excel close;

Ksharp_0-1663329013698.png

 

View solution in original post

3 REPLIES 3
Ksharp
Super User
data have;
  infile datalines truncover dlm=',' dsd;
  input catX $ catY $ value $ ALFA $;
  datalines;
X1,Y1,2,A
X1,Y1,4,D
X1,Y2,1,G
X1,Y2,3,H
X2,Y1,2,K
X2,Y2,2,H
X2,Y2,3,Y
X2,Y2,3,G
X1,Y3,2,A
X1,Y3,4,D
X1,Y4,2,A
X1,Y4,4,D
X2,Y4,2,A
X2,Y4,4,D
;
ods excel file='c:\temp\want.xlsx';
proc report data=have nowd out=temp;
  column  catY catX value  ALFA; 
define  catY/order noprint;
define catX /  order noprint;
define value/display 'A' style={just=r};
define ALFA / 'B' ;
 Compute before catX/style={just=l};
if catY=lag(catY) then len=0;
 else len=50;
Line  catY $varying50. len;
Line  catX $50.;
endcomp; 
run;
ods excel close;

Ksharp_0-1663250058793.png

 

Daily1
Quartz | Level 8
can it's possible to X1 and Y1 are seperate to different rows ?
Ksharp
Super User
data have;
  infile datalines truncover dlm=',' dsd;
  input catX $ catY $ value $ ALFA $;
  datalines;
X1,Y1,2,A
X1,Y1,4,D
X1,Y2,1,G
X1,Y2,3,H
X2,Y1,2,K
X2,Y2,2,H
X2,Y2,3,Y
X2,Y2,3,G
X1,Y3,2,A
X1,Y3,4,D
X1,Y4,2,A
X1,Y4,4,D
X2,Y4,2,A
X2,Y4,4,D
;
ods excel file='c:\temp\want.xlsx';
proc report data=have nowd style={cellwidth=2cm};
  column  catY catX value  ALFA; 
define  catY/order noprint;
define catX /  order noprint;
define value/display 'A' style={just=r};
define ALFA / 'B' ;
Compute before catX/style={just=l};
Line  catX $50.;
endcomp;
Compute before catY/style={just=l};
Line  catY $50. ;
endcomp; 
run;
ods excel close;

Ksharp_0-1663329013698.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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