Hello,
I am trying to figure out how to left align a column header in PROC REPORT, but what Im trying to do might not be possible I guess?
Piggy-backing off an earlier post, I am trying to left align the top column header in the last PROC REPORT section:
PROC SQL NOPRINT ;
SELECT SUM(msrp) format=18.2 INTO :total_msrp TRIMMED
FROM sashelp.cars ;
QUIT ;
PROC SQL ;
CREATE TABLE work.make_classification AS
SELECT
make ,
COUNT(*) AS COUNT FORMAT=comma11. ,
SUM(msrp) AS MSRP_SUM FORMAT=dollar18.2 ,
DIVIDE(CALCULATED MSRP_SUM, &total_msrp.) AS MSRP_PCTSUM FORMAT=percent12.3 ,
MAX(weight) AS W_MAX FORMAT=10. ,
AVG(mpg_city) AS MPGC_AVG FORMAT=10. ,
MAX(mpg_city) AS MPGC_MAX FORMAT=10. ,
AVG(mpg_highway) AS MPGH_AVG FORMAT=10. ,
MAX(mpg_highway) AS MPGH_MAX FORMAT=10. ,
AVG(horsepower) AS HP_AVG FORMAT=5.
FROM
sashelp.cars
GROUP BY
make
ORDER BY
MSRP_PCTSUM DESC ;
QUIT ;
ODS ESCAPECHAR = "^" ;
PROC REPORT DATA=work.make_classification MISSING ;
COLUMNS ("^{style[textalign=left]How can I left align this text?}" make COUNT ("msrp" MSRP_SUM MSRP_PCTSUM)
("weight" W_MAX) ("mpg_city" MPGC_AVG MPGC_MAX) ("mpg_highway" MPGH_AVG MPGH_MAX) ("horsepower" HP_AVG)) ;
DEFINE make / ORDER ORDER=DATA ;
DEFINE COUNT / SUM "Count" ;
DEFINE MSRP_SUM / SUM "Total" ;
DEFINE MSRP_PCTSUM / SUM "% of Total" ;
DEFINE W_MAX / DISPLAY "Max" ;
DEFINE MPGC_AVG / DISPLAY "Average" ;
DEFINE MPGC_MAX / DISPLAY "Max" ;
DEFINE MPGH_AVG / DISPLAY "Average" ;
DEFINE MPGH_MAX / DISPLAY "Max" ;
DEFINE HP_AVG / DISPLAY "Average" ;
RBREAK AFTER / SUMMARIZE STYLE=header[font_style=italic] ;
COMPUTE AFTER ;
CALL DEFINE("make", "style", 'style=header[pretext="Grand Totals" textalign=right]') ;
ENDCOMP ;
RUN ;
The above "^{style[textalign=left] text to align}" does not seem to work, and if I add some other style options in the PROC REPORT statement and each DEFINE line, then the other column headers are left aligned, not JUST the top one
PROC REPORT DATA=work.make_classification MISSING STYLE(header)=[textalign=left] ;
COLUMNS ("How can I left align ^{style [textdecoration=underline]ONLY} this text?" make COUNT ("msrp" MSRP_SUM MSRP_PCTSUM)
("weight" W_MAX) ("mpg_city" MPGC_AVG MPGC_MAX) ("mpg_highway" MPGH_AVG MPGH_MAX) ("horsepower" HP_AVG)) ;
DEFINE make / ORDER ORDER=DATA STYLE(header)=[textalign=center] ;
DEFINE COUNT / SUM "Count" STYLE(header)=[textalign=center] ;
DEFINE MSRP_SUM / SUM "Total" STYLE(header)=[textalign=center] ;
DEFINE MSRP_PCTSUM / SUM "% of Total" STYLE(header)=[textalign=center] ;
DEFINE W_MAX / DISPLAY "Max" STYLE(header)=[textalign=center] ;
DEFINE MPGC_AVG / DISPLAY "Average" STYLE(header)=[textalign=center] ;
DEFINE MPGC_MAX / DISPLAY "Max" STYLE(header)=[textalign=center] ;
DEFINE MPGH_AVG / DISPLAY "Average" STYLE(header)=[textalign=center] ;
DEFINE MPGH_MAX / DISPLAY "Max" STYLE(header)=[textalign=center] ;
DEFINE HP_AVG / DISPLAY "Average" STYLE(header)=[textalign=center] ;
RBREAK AFTER / SUMMARIZE STYLE=header[font_style=italic] ;
COMPUTE AFTER ;
CALL DEFINE("make", "style", 'style=header[pretext="Grand Totals" textalign=right]') ;
ENDCOMP ;
RUN ;
Any help is appreciated, Thank you!
Hi:
You would have more control if you used COMPUTE BEFORE _PAGE_ instead of a spanning header. Here's what I mean:
PROC REPORT DATA=sashelp.cars MISSING ;
COLUMNS make n ("msrp" msrp=msrp_sum msrp=msrp_pctsum)
("weight" weight) ("mpg_city" mpg_city=MPGC_AVG mpg_city=MPGC_MAX)
("mpg_highway" mpg_highway=MPGH_AVG mpg_highway=MPGH_MAX)
("horsepower" horsepower=HP_AVG) ;
where substr(make,1,1) le 'K';
DEFINE make / group ORDER=DATA ;
DEFINE N / "Count" f=comma11. ;
DEFINE MSRP_SUM / SUM "Total" f=dollar18.2 ;
DEFINE MSRP_PCTSUM / PCTSUM "% of Total" f=percent12.3 ;
DEFINE weight / Max "Max" f=10.;
DEFINE MPGC_AVG / mean "Average" f=10.;
DEFINE MPGC_MAX / max "Max" f=10.;
DEFINE MPGH_AVG / mean "Average" f=10.;
DEFINE MPGH_MAX / max "Max" f=10.;
DEFINE HP_AVG / mean "Average" f=5.;
RBREAK AFTER / SUMMARIZE STYLE=header[font_style=italic] ;
compute before _page_ / style=Header{textalign=left};
line 'How can I left align this text?';
endcomp;
COMPUTE AFTER;
Make = "Grand Totals";
CALL DEFINE("make", "style", 'style=header[textalign=right]') ;
ENDCOMP ;
RUN ;
I just did everything in PROC REPORT because seemed to be what you wanted and I cut the subset down so it ended with Kia, just to make the screen shot more managable.
Here's the output:
Hope this heps,
Cynthia
Trick it? Add some non breaking spaces to the end of the string.
%let pad=%sysfunc(repeat(%sysfunc(inputc(A0,$hex2.)),120));
ODS ESCAPECHAR = "^" ;
PROC REPORT DATA=work.make_classification MISSING ;
COLUMNS ("How can I left align ^{style [textdecoration=underline]ONLY} this text?&pad."
make COUNT ("msrp" MSRP_SUM MSRP_PCTSUM)
("weight" W_MAX) ("mpg_city" MPGC_AVG MPGC_MAX) ("mpg_highway" MPGH_AVG MPGH_MAX) ("horsepower" HP_AVG)) ;
DEFINE make / ORDER ORDER=DATA ;
DEFINE COUNT / SUM "Count" ;
DEFINE MSRP_SUM / SUM "Total" ;
DEFINE MSRP_PCTSUM / SUM "% of Total" ;
DEFINE W_MAX / DISPLAY "Max" ;
DEFINE MPGC_AVG / DISPLAY "Average" ;
DEFINE MPGC_MAX / DISPLAY "Max" ;
DEFINE MPGH_AVG / DISPLAY "Average" ;
DEFINE MPGH_MAX / DISPLAY "Max" ;
DEFINE HP_AVG / DISPLAY "Average" ;
RBREAK AFTER / SUMMARIZE STYLE=header[font_style=italic] ;
COMPUTE AFTER ;
CALL DEFINE("make", "style", 'style=header[pretext="Grand Totals" textalign=right]') ;
ENDCOMP ;
RUN ;
Hi:
You would have more control if you used COMPUTE BEFORE _PAGE_ instead of a spanning header. Here's what I mean:
PROC REPORT DATA=sashelp.cars MISSING ;
COLUMNS make n ("msrp" msrp=msrp_sum msrp=msrp_pctsum)
("weight" weight) ("mpg_city" mpg_city=MPGC_AVG mpg_city=MPGC_MAX)
("mpg_highway" mpg_highway=MPGH_AVG mpg_highway=MPGH_MAX)
("horsepower" horsepower=HP_AVG) ;
where substr(make,1,1) le 'K';
DEFINE make / group ORDER=DATA ;
DEFINE N / "Count" f=comma11. ;
DEFINE MSRP_SUM / SUM "Total" f=dollar18.2 ;
DEFINE MSRP_PCTSUM / PCTSUM "% of Total" f=percent12.3 ;
DEFINE weight / Max "Max" f=10.;
DEFINE MPGC_AVG / mean "Average" f=10.;
DEFINE MPGC_MAX / max "Max" f=10.;
DEFINE MPGH_AVG / mean "Average" f=10.;
DEFINE MPGH_MAX / max "Max" f=10.;
DEFINE HP_AVG / mean "Average" f=5.;
RBREAK AFTER / SUMMARIZE STYLE=header[font_style=italic] ;
compute before _page_ / style=Header{textalign=left};
line 'How can I left align this text?';
endcomp;
COMPUTE AFTER;
Make = "Grand Totals";
CALL DEFINE("make", "style", 'style=header[textalign=right]') ;
ENDCOMP ;
RUN ;
I just did everything in PROC REPORT because seemed to be what you wanted and I cut the subset down so it ended with Kia, just to make the screen shot more managable.
Here's the output:
Hope this heps,
Cynthia
That works. Note you don't need to tell it to "left align". You can just tell it to start at the beginning of the line.
compute before _page_ / style=Header;
line @1 'How can I left align this text?';
endcomp;
Thank you very much, Cynthia! This is exactly what I wanted, and exactly what I needed!
The reason I added the extra PROC SQL step was because in my actual situation I need the output to be in descending MSRP_PCTSUM order, and without and values in the summary line except for the N, SUM and PCTSUM columns.
I did not know of a way to do this via PROC REPORT alone.
Thank you again for your help!!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.