BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASaholic629
Fluorite | Level 6
  • I have 3 variables - Quarter (char), Bucket (char), Value (numeric)
  • I want to us Proc Report to display Quarter going across, and Bucket going down
  • When I do that using the code below, it is not grouping the Bucket going down, but rather duplicating Buckets, so that each value for each quarter is on its own row.
DATA Have;
INFILE DATALINES MISSOVER DELIMITER='|';
INPUT Qtr :$4. Bucket :$1. Value 8.;
DATALINES;
20Q4|A|10
20Q4|B|15
20Q4|C|20
21Q1|A|11
21Q1|B|14
21Q1|C|22
21Q2|A|12
21Q2|B|15
21Q2|C|23
;RUN;

ODS EXCEL FILE="FILEPATH/OutputFile.xlsx";

PROC REPORT DATA=Have;
TITLE 'Quarterly';
COLUMNS	Bucket Qtr,(Value);
	DEFINE Bucket	/ 'Bucket'	DISPLAY	STYLE=[CELLWIDTH=1.1in FONT_WEIGHT=BOLD];
	DEFINE Qtr		/ ' '		ACROSS ' ';
	DEFINE Value	/ 'Value'	DISPLAY	STYLE=[CELLWIDTH=1.1in];
RUN;

ODS EXCEL CLOSE;

 

The result looks like this:

 

 20Q421Q121Q2
BucketValueValueValue
A10..
B15..
C20..
A.11.
B.14.
C.22.
A..12
B..15
C..23

 

 

But I want the result to look like this (including creating a total row for each quarter):

 

 20Q421Q121Q2
BucketValueValueValue
A101112
B151415
C202223
Total454750

 

Is this possible to do, so that when new quarters are added to the data, it will automatically add a new column for the new quarter? And, of course, group them all on the same row for the same bucket.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

It is not grouping on bucket because you defined it as DISPLAY.

 

PROC REPORT DATA=Have;
TITLE 'Quarterly';
COLUMNS	Bucket Qtr,(Value);
	DEFINE Bucket	/ 'Bucket'	group	STYLE=[CELLWIDTH=1.1in FONT_WEIGHT=BOLD];
	DEFINE Qtr		/ ' '		ACROSS ' ';
	DEFINE Value	/ 'Value'	sum	STYLE=[CELLWIDTH=1.1in];
   rbreak after / summarize;
RUN;

View solution in original post

1 REPLY 1
data_null__
Jade | Level 19

It is not grouping on bucket because you defined it as DISPLAY.

 

PROC REPORT DATA=Have;
TITLE 'Quarterly';
COLUMNS	Bucket Qtr,(Value);
	DEFINE Bucket	/ 'Bucket'	group	STYLE=[CELLWIDTH=1.1in FONT_WEIGHT=BOLD];
	DEFINE Qtr		/ ' '		ACROSS ' ';
	DEFINE Value	/ 'Value'	sum	STYLE=[CELLWIDTH=1.1in];
   rbreak after / summarize;
RUN;

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
  • 1 reply
  • 363 views
  • 1 like
  • 2 in conversation