BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

Hello,

 

I have another question regarding aligning percentages in PROC Report. So currently my output is slightly off.

 

smackerz1988_0-1666195687270.png

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

 

smackerz1988_1-1666196077316.png

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);

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

ballardw
Super User

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.

smackerz1988
Pyrite | Level 9
  **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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 543 views
  • 0 likes
  • 3 in conversation