How to calculate 0.5 class interval of interest rates

Reply
Frequent Contributor
Posts: 87

How to calculate 0.5 class interval of interest rates

I have data set

data test;

input intrest count sum;

datalines;

0.4 1 100

0.6 1 150

1.2 1 40

1.8 1 30

2.1 1 20

0.3 1 20

0.2 1 30

1.6 1 40

2.2 1 60

;

run;

i need to divide the interval based on 0.5 automatically as shown in output and display count and sum of values

output should be

INTREST_RATE   COUNT   SUM

>= 0 - < 0.5    3      150

>= 0.5 - < 1    1      150

>= 1 - < 1.5    1       40

>= 1.5 - < 2    1       30  

>= 2 - < 2.5    2       80

can any one help

SAS Employee
Posts: 20

Re: How to calculate 0.5 class interval of interest rates

By using a user defined format you can achieve the desired output:

/* Create a user written format to group the intrest values in 0.5 intervals */

data fmtdata ;

  fmtname = 'intrest'; /* Format name */

  sexcl = 'N'; /* Exclude Start value from interval: No */

  eexcl = 'Y'; /* Exclude End value from interval: Yes   */

  do start=0 to 100 by 0.5;

    end = start + 0.5;

    label = catx(' ',put(start,5.1),'- <',put(end,5.1));

    output;

  end;

  format start end 10.5;

run; 

/* Create the format */

proc format cntlin=fmtdata;

run;

data test;

input intrest countvar sumvar;

datalines;

0.4 1 100

0.6 1 150

1.2 1 40

1.8 1 30

2.1 1 20

0.3 1 20

0.2 1 30

1.6 1 40

2.2 1 60

3.5 1 100

;

run;

/* Create the report */

proc tabulate data=test ;

  class intrest / preloadfmt;

  format intrest intrest.;

  var countvar sumvar;

  table intrest ALL='Total',(N='Count' sumvar=''*sum='Sum'*f=8.)

        ;

run;

Regards,

Michael

Ask a Question
Discussion stats
  • 1 reply
  • 358 views
  • 0 likes
  • 2 in conversation