BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

data have1;

input Mgr $ Exception $ CNT ;

datalines;

 

Smith Transfer 1

Smith Transfer 1

Smith Cancel 1

Brown Reinstate 1

Brown Terminate 1

Saunders Transfer 1

Saunders Cancel 1

;run;

proc sort data=have1;by exception;run;

proc transpose data= have1 out=have2 (drop= _NAME_ _LABEL_) let prefix=mgr_;

id Mgr;

by Exception;

var cnt;

run;

 

I want to do a proc report.  However the Mgr may expand to more than 3 (currently Smith,Brown and Saunders) or it may contract. Currently I would need to hard-code each Mgr in the proc report.  Is there a way to dynamically display the Mgr side by side and account for changes dynamically ?? 

proc report data=have1 wrap style(column)={just=center};

title 'Summary';

column Exception Mgr cnt ;

define Exception / group style (column)=[cellwidth=100pt] "EXC TYPE";

Define ???MGR????

/*define /group style(column)=[cellwidth=100pt] "MANAGER";*/

define cnt / sum "Total" style(column)=[cellwidth=90pt];

rbreak after / summarize style (summary)= Header;

compute after;

Exception = 'Total';

endcomp;

run;

title ;title2;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Consider

 

data have;
input Mgr $ Exception $ CNT ;
datalines;
Smith Transfer 1
Smith Transfer 1
Smith Cancel 1
Brown Reinstate 1
Brown Terminate 1
Saunders Transfer 1
Saunders Cancel 1
;
run;
proc report data=have     ;
   column Exception Mgr, cnt ;
   define Exception / group style (column)=[cellwidth=100pt] "EXC TYPE";
   Define mgr/ across;

   define cnt / sum "Total" style(column)=[cellwidth=90pt];
   rbreak after / summarize style (summary)= Header; 
   compute after;
      Exception = 'Total';
   endcomp;
run;

The comma between mgr and cnt on the columns statement says to "nest" the value or statistic for CNT with the value of MGR.

And the across define for mgr makes the columns based on the values of the MGR variable.

May want to suppress the labels for MGR and possibly CNT though.

View solution in original post

2 REPLIES 2
ed_sas_member
Meteorite | Level 14
Hi @Q1983
I think you don’t need to transpose your data.
You can use the raw data directly.
As you’ve define the variable exception as the ´group‘ variable in the proc report, you can define the variable Mgr as the ‘across’ variable.
ballardw
Super User

Consider

 

data have;
input Mgr $ Exception $ CNT ;
datalines;
Smith Transfer 1
Smith Transfer 1
Smith Cancel 1
Brown Reinstate 1
Brown Terminate 1
Saunders Transfer 1
Saunders Cancel 1
;
run;
proc report data=have     ;
   column Exception Mgr, cnt ;
   define Exception / group style (column)=[cellwidth=100pt] "EXC TYPE";
   Define mgr/ across;

   define cnt / sum "Total" style(column)=[cellwidth=90pt];
   rbreak after / summarize style (summary)= Header; 
   compute after;
      Exception = 'Total';
   endcomp;
run;

The comma between mgr and cnt on the columns statement says to "nest" the value or statistic for CNT with the value of MGR.

And the across define for mgr makes the columns based on the values of the MGR variable.

May want to suppress the labels for MGR and possibly CNT though.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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