Hi all,
Can you think of a way to create this report from this data ?
data HAVE;
input ROW COL VALUE;
cards;
R1 C1 x
R1 C2 y
R1 C1 x1
R1 C2 y
R2 C1 x
R2 C2 z
R2 C1 x
R2 C2 z
R2 C2 z
run;
Thank you!
data HAVE; input( ROW COL VALUE) ($); cards; R1 C1 x R1 C2 y R1 C1 x1 R1 C2 y R2 C1 x R2 C2 z R2 C1 x R2 C2 z R2 C2 z ; run; proc freq data=have noprint; table row*col*value/out=temp list; run; proc report data=temp nowd ; column row col,(value count); define row/group; define col/across ' '; define value/display ; run;
data HAVE; input( ROW COL VALUE) ($); cards; R1 C1 x R1 C2 y R1 C1 x1 R1 C2 y R2 C1 x R2 C2 z R2 C1 x R2 C2 z R2 C2 z ; run; proc freq data=have noprint; table row*col*value/out=temp list; run; proc report data=temp nowd ; column row col,(value count); define row/group; define col/across ' '; define value/display ; run;
Nice! Thank you!
Any way to move the
y | 2 |
on line up, together with the x rather than the x1 ?
This:
C1 | C2 | |||
---|---|---|---|---|
ROW | VALUE | Frequency Count | VALUE | Frequency Count |
R1 | x | 1 | y | 2 |
x1 | 1 | . | ||
R2 | x | 2 | z | 3 |
instead of
C1 | C2 | |||
---|---|---|---|---|
ROW | VALUE | Frequency Count | VALUE | Frequency Count |
R1 | x | 1 | . | |
x1 | 1 | y | 2 | |
R2 | x | 2 | z | 3 |
I tried this to put the lines in the right order in the data set, but the report is unchanged.
proc freq data=HAVE noprint;
table ROW*COL*VALUE/out=FREQ ;
run;
data SORTED;
set FREQ;
by ROW COL;
if first.COL then LINE=0;
LINE+1;
run;
proc sort;
by ROW LINE COL;
run;
proc report data=SORTED nowd ;
column ROW COL,(VALUE count);
define ROW /group;
define COL /across ' ';
define VALUE/display ;
label count='#';
run;
Got it!
proc report data=SORTED nowd ;
column ROW LINE COL,(VALUE count);
define ROW /group;
define LINE /group noprint;
define COL /across ' ';
define VALUE /display ;
label count='#';
run;
Chris, Well done. Never thought that before. Learn something new from you !
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.