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 .
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.