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

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;

 

aaa1.PNG

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User


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;

View solution in original post

6 REPLIES 6
Ksharp
Super User


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;

ChrisNZ
Tourmaline | Level 20

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

 

 

 

 

Ksharp
Super User
Really uneasy. Can't you Data step to get it like MERGE and then PROC REPORT ?
ChrisNZ
Tourmaline | Level 20

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;

 

 

 

ChrisNZ
Tourmaline | Level 20

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;

 

Ksharp
Super User
Chris,
Well done. Never thought that before. Learn something new from you !

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2519 views
  • 1 like
  • 2 in conversation