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
SAS Super FREQ

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
SAS Super FREQ

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 22 replies
  • 1531 views
  • 6 likes
  • 4 in conversation