BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

data rawdata ;
input var1 total ;
/*calculating percentages*/
percentage=put(var1,5.)||'('||put((var1*100)/total,5.1)||')';
cards ;
23 169
33 169
23.5 169
2 30
12 43
12.342
run;

 

I am calculating percentages and need to set correct alignement like
while generating report part output alignment should be like:


Percentages
  23 (  50.2   %)

    2 (    3      %) 

324 (  99.23 %)

 

 

4 REPLIES 4
s_lassen
Meteorite | Level 14

Your "desired" output is actually not aligned. If you look at it in a fixed-length typeset it looks like this:

  23 (  50.2   %)
    2 (    3      %) 
324 (  99.23 %)

The blanks are a lot shorter in the Arial font you are using, which is what makes your "desired" output look "aligned" when presented on the web page in that font. 

 

If you, on the other hand, take the output from your program, and show it in a non-proportional font, it looks like this:

    23( 13.6)        
    33( 19.5)        
    24( 13.9)        
     2(  6.7)        
    12( 97.6)  

- which is aligned OK, you just need to add some blanks and a percentage sign to make it look allright. 

 

So perhaps you could overcome the problem by presenting the report in a font like Courier.

 

 

 

 

thanikondharish
Calcite | Level 5
We don't know how many decimals will come
s_lassen
Meteorite | Level 14

@thanikondharish wrote:
We don't know how many decimals will come

Unless the numbers are divisible, the percentages will have about 15 significant decimals. if one number is 1 and the other 3, the floating-point number will contain this: "33.3333333333333". You will just have to make a decision about how many of those decimals you want to present, by changing the format to e.g. 6.3, or perhaps 16.13, if you really want all decimals there.

 

It may look "bad" to you to have the number 3 represented as " 3.000", but is that really a problem?

 

In that case you could replace trailing zeroes (and decimal signs) with blanks like this:

data rawdata ;
input var1 total ;
/*calculating percentages*/
percentage=' '||put(var1,3.)||' ( '||put((var1*100)/total,5.2)||' %)';
prxid=prxparse('/\.?0+ /');
start=1;
len=0;
pos=0;
call prxnext(prxid,start,-1,percentage,pos,len);
if pos then 
  substr(percentage,pos,len)='';
put percentage $20.;
drop start prxid pos len;
cards ;
23 169
33 169
23.5 169
2 20
1 200
12.043 12.342
;run;

The regular expression tries to find one or zero decimal points (\.?), followed by one or more zeroes, and finally a blank. If the search is successful, the string found is blanked out.

Ksharp
Super User

Using " just=dec" style .If you are using RTF destination.

 

data rawdata ;
input var1 total ;
/*calculating percentages*/
percentage=put(var1,5.)||'('||put((var1*100)/total,5.1)||')';
cards ;
23 169
33 169
23.5 169
2 30
12 43
12.342
;
run;

ods rtf file='c:\temp\temp.rtf' style=journal;
proc report data=rawdata nowd;
define percentage /display style(column)={just=dec};
run;
ods rtf close;

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
  • 4 replies
  • 671 views
  • 1 like
  • 3 in conversation