should have zero decimal places

Reply
N/A
Posts: 1

should have zero decimal places

Hi,

please someone help me on this.

In below datset i have used round function, i got the output 98.46%, 54.86%.  My requirement is instead of 98.46% and 54.86% i need only 98  54 only.

data &final_per;

COL1=round(&per1*100/&per_1)||"%";

COL2=round(&per2*100/&per_2)||"%";

COL3=round(&per3*100/&per_3)||"%";

COL4=round(&per4*100/&per_4)||"%";

COL5=round(&per5*100/&per_5)||"%";

COL6=round(&per6*100/&per_6)||"%";

COL7=round(&per7*100/&per_7)||"%";

COL8=round(&per8*100/&per_8)||"%";

COL9=round(&per9*100/&per_9)||"%";

COL10=round(&per10*100/&per_10)||"%";

COL11=round(&per11*100/&per_11)||"%";

COL12=round(&per12*100/&per_12)||"%";

run;

%mend;

Super Contributor
Posts: 1,636

Re: should have zero decimal places

Posted in reply to kiranreddy

Hi,

Try replacing round with int.

Respected Advisor
Posts: 3,156

Re: should have zero decimal places

Or floor()

Haikuo

Trusted Advisor
Posts: 1,301

Re: should have zero decimal places

data _null_;

input pct @@;

put=put(pct,percent.);

* use cats() function to avoid note in log about numeric -> character conversion;

round=cats(round(pct*100,1),'%');

int=cats(int(pct*100),'%');

floor=cats(floor(pct*100),'%');

ceil=cats(ceil(pct*100),'%');

put (_all_) (=/);

cards;

.01123 .1235644 .386785654 .588865 .9456 1.4336 2.60000 3.0234 4.500000001

;

run;

pct=0.01123

put=1%

round=1%

int=1%

floor=1%

ceil=2%

pct=0.1235644

put=12%

round=12%

int=12%

floor=12%

ceil=13%

pct=0.386785654

put=39%

round=39%

int=38%

floor=38%

ceil=39%

pct=0.588865

put=59%

round=59%

int=58%

floor=58%

ceil=59%

pct=0.9456

put=95%

round=95%

int=94%

floor=94%

ceil=95%

pct=1.4336

put=143%

round=143%

int=143%

floor=143%

ceil=144%

pct=2.6

put=260%

round=260%

int=260%

floor=260%

ceil=260%

pct=3.0234

put=302%

round=302%

int=302%

floor=302%

ceil=303%

pct=4.500000001

put=450%

round=450%

int=450%

floor=450%

ceil=451%

Respected Advisor
Posts: 3,799

Re: should have zero decimal places

Posted in reply to kiranreddy

To me it appears the only way you can get the values rounded to two decimal places is for &PER_n to include the rounding units.  The thing I don't understand is why you have put you data into macro variables, but I suppose that is a difference discussion.


%let per1=87;
%let per_1=99,.01;

data _null_;
   COL1=round(&per1*
100/&per_1)||"%";
  
put col1=;
   run;
Super Contributor
Posts: 1,636

Re: should have zero decimal places

Posted in reply to data_null__

DN, the OP doesn't want any decimal places.

Respected Advisor
Posts: 3,799

Re: should have zero decimal places

Linlin wrote:

DN, the OP doesn't want any decimal places.

Yes I understand.  I was trying to figure out by looking at the code snipit how ROUND with null second argument would have produced a number with two places.   Problem is we don't know what the value of the macro variables are.

Super User
Posts: 19,851

Re: should have zero decimal places

Posted in reply to kiranreddy

I suggest using an array a percent format or a put with percent format if you really need it.

data &final_per;


array col(12) col1-col12;

array per(12) per1-per12;

array per_(12) per_1-per_12;

array ex(12) ex1-ex12;


do i=1 to 12;

     col(i)=per(i)/per_(i);

     ex(i)=put(per(i)/per_(i), percent8.);

end;

format col: percent8.;

run;


Super User
Posts: 11,343

Re: should have zero decimal places

Posted in reply to kiranreddy

I think we need to see what values the OP is using in those macro variables. As I get integer type values for quite a few ranges of macro variables. For example if &per_1 resolves to something like 25, 2 then that is asking round to return 2 decimals.

Ask a Question
Discussion stats
  • 8 replies
  • 423 views
  • 0 likes
  • 7 in conversation