Hi,
i'm trying to set colomns width for each column of an across variable in a proc report.
This is my dataset structure:
STRATA1 | STRATA2 | _NAME_ | COL1 |
CAT1 | CAT2 | NObs1 | xx |
CAT1 | CAT2 | mean | xxx |
CAT1 | CAT2 | std | xxx |
CAT1 | CAT2 | median | xxx |
CAT1 | CAT2 | Q13 | xxx; xxx |
CAT1 | CAT2 | Minmax | xxx; xxx |
This is the format code:
proc format ;
value $label
"N" = "N"
"NObs1" = "n"
"mean" = "Mean"
"median" = "Median"
"std" = "Std Dev"
"Q13" = "Q1; Q3"
"Minmax" = "Min; Max"
;
run;
This is the proc report code:
goptions device=png;
ods listing close;
options nodate nonumber orientation = landscape nobyline;
ods rtf file= "file.rtf" style = customtemp;
title1 j=l "title";
proc report data=report missing nowd split="|" style(header)={just = center} ;
columns ("" STRATA1 STRATA2) ( _NAME_,(COL1)) dummy ;
define STRATA2 /' ' group style(column)={cellwidth=0.08in just = left};
define STRATA1 /' ' group style(column)={cellwidth=0.08in just = left};
define _NAME_ /' ' nozero across order = data style(column)={just = center} format = $label.;
define COL1 /' ' style(column)={cellwidth=0.10in just = center};
define dummy /computed noprint;
compute _NAME_;
if compress(_NAME_) = 'NObs1' then call define(_col_, "style/merge", "style=[cellwidth=0.03in]");
else if compress(_NAME_) = 'mean' then call define(_col_, "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'median' then call define(_col_, "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'std' then call define(_col_, "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'Q13' then call define(_col_, "style/merge", "style=[cellwidth=0.05in]");
else if compress(_NAME_) = 'Minmax' then call define(_col_, "style/merge", "style=[cellwidth=0.05in]");
endcomp;
run;
ods rtf close;
It does not change the columns width.
I also tryed with the following code with the same result.
compute _NAME_;
if compress(_NAME_) = 'NObs1' then call define('NObs1', "style/merge", "style=[cellwidth=0.03in]");
else if compress(_NAME_) = 'mean' then call define('mean', "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'median' then call define('median', "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'std' then call define('std', "style/merge", "style=[cellwidth=0.04in]");
else if compress(_NAME_) = 'Q13' then call define('Q13', "style/merge", "style=[cellwidth=0.05in]");
else if compress(_NAME_) = 'Minmax' then call define('Minmax', "style/merge", "style=[cellwidth=0.05in]");
endcomp;
could you help me?
0.04in and similar is likely the culprit. A cell that small very likely does not have room for more than one character.
Are you getting any messages in the log?
Here is an example of using a format to set the width of the column based on the value of the Name.
proc format; value $cw "N" = ".5in" "NObs1" = "1in" "median" = "1.5in" ; run; data junk; input row name $ value; datalines; 1 N 2300 2 Nobs1 110 3 median 17.4 ; proc report data=junk; columns row name, value; define row /group; define name /across style=[cellwidth=$cw.]; run;
You can use the same approach to change font, text color, background color and most items that appear in a style block for a cell.
0.04in and similar is likely the culprit. A cell that small very likely does not have room for more than one character.
Are you getting any messages in the log?
Here is an example of using a format to set the width of the column based on the value of the Name.
proc format; value $cw "N" = ".5in" "NObs1" = "1in" "median" = "1.5in" ; run; data junk; input row name $ value; datalines; 1 N 2300 2 Nobs1 110 3 median 17.4 ; proc report data=junk; columns row name, value; define row /group; define name /across style=[cellwidth=$cw.]; run;
You can use the same approach to change font, text color, background color and most items that appear in a style block for a cell.
Thank you very much!! I had not considered the possibility of providing the information as a format, real interesting solution. ps. there was no erorr in the log
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.