Hello,
I have another question regarding aligning percentages in PROC Report. So currently my output is slightly off.
how can I consistently align them so they are the same regardless of the number and spacing. This would be the ideal output based on the example provided
Here is my code currently
%macro output(col=,
page=);
proc report data = page missing style=VeraRTF style(report)=[width=100% ] &_reportopts.;
column paramn aval cond1 paramn &col.;
/* Non printed order variables */
define paramn / order order=internal noprint;
define aval / order order=internal noprint;
/* Non printed variable used for indenting */
define cond1 / noprint;
define col1 / id " " order order = internal style(column)=[width=28% asis=on just=l]
style(header)=[width=28% asis=on just=l];
%if &page. = 1 %then %do;
define col2 / id " " order order = internal style(column)=[width=3% asis=on just=l ];
define col3 / order order = internal style(column)=[width=11% asis=on just=l leftmargin = 2.5%];
define col4 / order order = internal style(column)=[width=11% asis=on just=l leftmargin = 2.5%];
define col5 / order order = internal style(column)=[width=11% asis=on just=l leftmargin = 2.5%];
define col6 / order order = internal style(column)=[width=11% asis=on just=l leftmargin = 2.5%];
%end;
%if &page. = 2 %then %do;
define col7 / page order order = internal style(column)=[width=11% asis=on just=l leftmargin = 2.5%];
define col8 / order order = internal style(column)=[width=10% asis=on just=l leftmargin = 2.5%];
define col9 / order order = internal style(column)=[width=8% asis=on just=l leftmargin = 2.5%];
define col10 / order order = internal style(column)=[width=8% asis=on just=l leftmargin = 2.5%];
define col11 / order order = internal style(column)=[width=8% asis=on just=l leftmargin = 2.5%];
%end;
* Col1 indent *;
compute col1;
if cond1 eq 'Y' then call define(_col_, "style/merge", "style=[leftmargin=1.6%]");
endcomp;
*Skip line *;
compute before paramn;
line " ";
endcomp;
run;
%mend;
%output(col = col1 col2 col3 col4 col5 col6,
page = 1);
%output(col = col1 col7 col8 col9 col10 col11,
page = 2);
Personally I would say that your Count, or what ever the 2 represents is what is off.
Show how you make those strings. I guess that you are concatenating a value of 2 with the percentage. I would say the part creating 2 (and all of those 0s which are also not aligned) should be using a different approach but without seeing exactly what you are doing it is hard to make a recommendation..
PS You are not aligning percentages, you are aligning character values. Which will likely have problem if you ever display this result with anything other than a fixed width font like Courier or SAS Monospace.
You show us code for 5 variables, but your report seems to contain 12.
Also, without knowing the data used to create the report, the code alone is not useful.
So please post a sample of your data in usabke form (dara step with datalines, DO NOT SKIP THIS!), and your complete code, from PROC REPORT to RUN.
Personally I would say that your Count, or what ever the 2 represents is what is off.
Show how you make those strings. I guess that you are concatenating a value of 2 with the percentage. I would say the part creating 2 (and all of those 0s which are also not aligned) should be using a different approach but without seeing exactly what you are doing it is hard to make a recommendation..
PS You are not aligning percentages, you are aligning character values. Which will likely have problem if you ever display this result with anything other than a fixed width font like Courier or SAS Monospace.
**Construct character variable parts;
if aval gt 0 then do;
if denom le 0 or count le 0 then numpart = '0';
else numpart = trim(left(put(count,8.)));
if denom le 0 or count le 0 then pctpart = '';
else pctpart = trim(left(put(round(count*100/denom, 0.1), pct1dp.)));
end;
run;
**Find space required for each part ;
proc sql noprint;
select max(max(lengthn(strip(numpart))),1),
max(max(lengthn(strip(pctpart))),1) into :numlength, :pctlength
from all_counts;
quit;
** Produce formatted results;
data npct;
length result $34;
set all_counts;
lengthr=length(numpart);
if lengthr = 1 then do;
result = right(put(numpart, 3.)) || ' ' || right(put(pctpart, &pctlength..));
end;
if lengthr = 2 then do;
result = right(put(numpart, 3.)) || ' ' || right(put(pctpart, &pctlength..));
end;
run;
This is how I'm constructing it and the lengthr coding is me trying to adjust for the issue
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.