Help using Base SAS procedures

Proc Summary or Proc Means - help needed

Reply
Contributor
Posts: 44

Proc Summary or Proc Means - help needed

Hi,

I have a dataset which I'd like to summarise in bands. 2 of my variables range in value from 0 to 100,000. I'd like to produce a report banding this data in groups of 5,000, i.e. summarise it in rows as follows:

0 - 5,000

5,000 - 10,000

10,000-15,000

...

95,000-100,000

Is there an easy way in which to do this, without having to do it programatically in a data step?

TIA

Respected Advisor
Posts: 3,777

Re: Proc Summary or Proc Means - help needed

You can create a user defined format.  You can even use a data step to create.

data cntl;

   retain fmtname 'FiveK' type 'n';

   do start = 0 to 95e3 by 5e3;

      end = start + 5000;

      label = catx('-',start,end);

      output;

      end;

   run;

proc print;

   run;

proc fmtlib cntlin=cntl;

  run;

Contributor
Posts: 44

Proc Summary or Proc Means - help needed

in the end I went with this:

Data xx;

     Set yy;

     Band = int(SumAssured/5000);

Run;

Then I sorted and summarised the dataset by Band. I was surprised it was so easy.

Thanks

Frequent Contributor
Posts: 104

Proc Summary or Proc Means - help needed

This worked because your bands are equal sized.  You still need a way to convert the band number to suitable display text though.

In general, you'll find PROC FORMAT to be your best friend in extremely flexible groupings like:

proc format;

     value band

          low - 0 = 'negative'

          0 - 1000 = 'low'

          1000 - 10000 = 'medium'

          10000 - 100000 = 'high'

          100000 - 1e6 = 'rich'

          1e6 - 1e9 = 'filthy rich'

          1e9 - high = 'obscene'

     ;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 153 views
  • 3 likes
  • 3 in conversation