Hello,
I am trying to rename my field to a new label name but the new label name is convoluted. I tried to use the width function within the style header to expand the field but it only made my column bigger.
This is my code:
proc report data=Table1_Final out=Table1_Final_1 spanrows style(header)=[fontweight=bold background=lightblue foreground=black width=50]
style(column)={font_face='Calibri' fontsize=11pt};
column Status P4 P3 P2 P1;
define Status / Display "";
define P1 / Analysis "7/1/20 - 12/31/2020" ;
define P2 / Analysis "4/1/20 - 09/30/2020";
define P3 / Analysis "1/1/20 - 06/30/2020";
define P4 / Analysis "10/1/19 - 03/31/2020";
title1 '# of Members Filling Opioids';
rbreak after / summarize;
compute status;
if _break_ in ('_RBREAK_') then do;
Status = 'Total';
end;
endcomp;
run;
I need to have my report to look like this:
10/1/19 - 03/31/2020 | 1/1/20 - 06/30/2020 | 4/1/20 - 09/30/2020 | 7/1/20 - 12/31/2020 | |
X1 | 470 | 479 | 485 | 507 |
X2 | 12.44 | 10.91 | 10.49 | 10.43 |
X3 | 23 | 26 | 26 | 31 |
X4 | 0.61 | 0.59 | 0.56 | 0.64 |
X5 | 493 | 505 | 511 | 538 |
X6 | 13.05 | 11.51 | 11.06 | 11.07 |
It would be output to Excel utilizing ODS.
1. This has nothing to so with proc export. Please change your title. Also make it more explicit like"proc report label width"
2. Please format your code using the appropriate icon when pasting it
3. Your question is unclear. What do you want to change?
I am sorry! I meant Proc Report. I am trying to have my label fit into the column and not have it convoluted like this:
WHICH label?
And what would the result look like?
Proc report doesn't make column heading widths different than the column (shuddering to think what that looks like). If the column is "too wide" when the current label is displayed the way you like then you have the choices of 1) reducing the amount of text in the column heading
2) changing the column heading text to a much smaller font so it might fit in the space you want. Something like
proc report data=sashelp.class; columns sex height; define sex/group; define height/ style(header)=[fontsize=6pt] "Some long text label"; run;
Not using lots of hyphens might help as well. SAS will think that a hyphen is an okay character to "break" a heading to fit into allotted space, just as it will a space.
Quick and dirty way is to split your label, in this example I used ~ as the split character.
Also you may wish to center and decimal align your numbers.
BTW, what is your output format, HTML or another?
proc report split='~' data=Table1_Final out=Table1_Final_1 spanrows style(header)=[fontweight=bold background=lightblue foreground=black]
style(column)={font_face='Calibri' fontsize=11pt};
column Status P4 P3 P2 P1;
define Status / Display "";
define P1 / Analysis "7/1/20 -~ 12/31/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P2 / Analysis "4/1/20 -~ 09/30/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P3 / Analysis "1/1/20 -~ 06/30/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P4 / Analysis "10/1/19 -~ 03/31/2020" style(column)={cellwidth=15% textalign=center just=decimal};
title1 '# of Members Filling Opioids';
rbreak after / summarize;
compute status;
if _break_ in ('_RBREAK_') then do;
Status = 'Total';
end;
endcomp;
run;
It would be output to Excel utilizing ODS.
@ghosh! Thank you so much! It worked!
If I want to merge two cells to create one cell called "Total".
This is my code:
proc report split='~' data=Table4_Final out=Table4_Final_2 spanrows style(header)=[fontweight=bold background=lightblue foreground=black]
style(column)={font_face='Calibri' fontsize=11pt};
column n_of_prescribers n_of_pharmacies P4 P3 P2 P1 Percent_of_Total_Opioid_Members Naloxone_Utilization Percentage_Naloxone;
define n_of_prescribers / Display "n of prescribers" style(column)={cellwidth=25% textalign=center just=decimal};
define n_of_pharmacies / Display "n of pharmacies" style(column)={cellwidth=25% textalign=center just=decimal};
define P1 / Analysis "7/1/20 -~ 12/31/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P2 / Analysis "4/1/20 -~ 09/30/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P3 / Analysis "1/1/20 -~ 06/30/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P4 / Analysis "10/1/19 -~ 03/31/2020" style(column)={cellwidth=15% textalign=center just=decimal};
define P1000m / Analysis "P1000m" style(column)={cellwidth=15% textalign=center just=decimal};
define Naloxone_Utilization / Analysis "Naloxone~Utilization (n)" style(column)={cellwidth=15% textalign=center just=decimal};
define Percentage_Naloxone / Analysis "Naloxone~Utilization (%)" style(column)={cellwidth=15% textalign=center just=decimal};
title1 'TABLE 4: All Opioid Members by # of Prescribers and Pharmacies';
rbreak after / summarize;
compute n_of_prescribers;
if _break_ in ('_RBREAK_') then do;
n_of_prescribers = 'Total';
end;
endcomp;
run;
I want it to look like this:
n of prescribers | n of pharmacies | 10/1/19 - 03/31/2020 | 1/1/20 - 06/30/2020 | 4/1/20 - 09/30/2020 | 7/1/20 - 12/31/2020 | % of Total Opioid Members | Naloxone Utilization (n) | Naloxone Utilization (%) |
n ≥ 6 | n ≥ 1 | - | - | - | - | 0.00% | 0 | #DIV/0! |
6 > n ≥ 4 | n ≥ 4 | - | - | - | - | 0.00% | 0 | #DIV/0! |
6 > n ≥ 4 | n = 3 | 1 | 1 | - | - | 0.00% | 0 | #DIV/0! |
6 > n ≥ 4 | n < 3 | 6 | 2 | 1 | 1 | 0.20% | 0 | 0.00% |
n = 3 | n ≥ 3 | - | - | - | 3 | 0.59% | 0 | 0.00% |
n = 3 | n < 3 | 8 | 5 | 7 | 7 | 1.38% | 0 | 0.00% |
n < 3 | n ≥ 3 | 5 | 2 | 2 | 1 | 0.20% | 0 | 0.00% |
n < 3 | n < 3 | 450 | 469 | 475 | 495 | 97.63% | 3 | 0.61% |
Totals | 470 | 479 | 485 | 507 | 100.00% | 3 | 0.59% |
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.