BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

Try it and let us know Smiley Happy

robertrao
Quartz | Level 8

Hi,

I have percentages calculated in the dataset and some of the values are like

75

62.924567

32

35.987543

After the above datastep is a SORT step to sort it from highest percentage to lowest percentage(because I was requested like that)

Later I am going for the REPORT PRocedure as shown below

In the Proc report Define statement  how can I make them look better

75.00%

62.92%

32.00%

35.99%

I am using define rate/display format=10.2  and I am not getting it right!!!!

Regards

Ksharp
Super User

format=best10.2   ?

robertrao
Quartz | Level 8

Wel. Thanks for the reply. Let me tell you my current situation.

I did the rate calculation in the datastep. and i have values like shown IN THE DATASET

75

62.924567

32

35.987543

I have to take this dataset and do a REPORT.

In the REPORT I want

75.00%

62.92%

32.00%

35.99%

BUT I SHOULD ALSO GET the 51.47% When i Summarize.

Is that possible

Cynthia_sas
Diamond | Level 26

Hi:

  OK...here's something to study on. I don't actually think you need ORDER=FREQ DESCENDING. Take a look at this example -- it uses SASHELP.CLASS and divides height.sum by weight.sum -- sort of a silly ratio, but shows division in the creation of the new "helper" variables RATEORD and RRATE. I did not hide RATEORD in the #3 report, but after you understand what's happening, you can use NOPRINT:

ods _all_ close;

ods listing;

 

proc report data=sashelp.class nowd out=rateout;

  title '1) Make 2 "extra" variables';

  column age height weight rrate rateord;

  define age / group;

  define height /sum;

  define weight/ sum;

  define rrate / computed;

  define rateord / computed;

  compute rrate;

    rrate = height.sum / weight.sum;

  endcomp;

  compute rateord;

    rateord = height.sum/weight.sum;

  endcomp;

run;

  

proc print data=rateout;

title '2) what is in RATEOUT dataset';

run;


proc sort data=rateout;
  by descending rateord age;
run;

ods listing close;

 
ods html file='c:\temp\rateout.html' style=sasweb;
proc report data=rateout nowd;
  title '3) Use RATEORD for ordering and use RRATE with % format';
  column rateord age height weight rrate;
  define rateord / order order=data /* noprint */;
  define age / order;
  define height / sum;
  define weight/sum;
  define rrate / f=percent9.2;
  rbreak after / summarize;
  compute rrate;
    if _break_ = '_RBREAK_' then do;
       ** calculate new overall rate for summary line;
       ** by dividing, or else rrate will be just added up;
       rrate.sum = height.sum / weight.sum;
    end;
  endcomp;
run;
ods html close;
ods listing;
title;


Note that I did not multiply by 100 in my formula - -there's no point because when I use the PERCENT format on RRATE, the decimal point will be shifted. If you don't want to display the % sign, then go ahead and multiply by 100. For situations like this, I prefer to use PROC SORT to get the sort order I want and then just use ORDER=DATA on the DEFINE statement. You did not say whether you wanted an "overall" ratio, so, just in case, you will want that, I put an RBREAK and a COMPUTE in the #3. If you don't want that, then just get rid of it.

cynthia


creating_rateord.png
robertrao
Quartz | Level 8

Excellent job.It works pretty Good. I was wasting a lot of time on this all this while.........Thanks a TON.........I now understand better a concept which I dint for a while....

You saved me amd my time........

THanks again

Regards

Cynthia_sas
Diamond | Level 26

Hi,
Glad that you got it working. In my opinion, time spent learning is never wasted.

cynthia

robertrao
Quartz | Level 8

Thanks. I have anothwer related question. I will post it as another question now..

Regards

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 22 replies
  • 3418 views
  • 6 likes
  • 4 in conversation