Division on obseravations

Reply
Regular Contributor
Posts: 233

Division on obseravations

Input:

PROMOTION                           TOTALS

TOTAL RECORDS                    3,329

TOTAL RECORDS ACCEPTED  3,089

TOTAL RECORDS REJECTED   240

Output:

PROMOTION                           TOTALS

TOTAL RECORDS                    3,329

TOTAL RECORDS ACCEPTED  3,089

TOTAL RECORDS REJECTED   240

Ratio                                        240/3089

Super User
Posts: 19,869

Re: Division on obseravations

data have;

        input promotion  totals;

        cards;

1 3329

2 3089

3 240

;

data want;

        set have end=eof;

        output;

        prev_total=lag(totals);

        if eof then do ;

               promotion=4;

               totals=totals/prev_total;

                   output;

        end;

run;

proc print data=want;run;

Respected Advisor
Posts: 3,156

Re: Division on obseravations

Or this:

data have;

input (PROMOTION TOTALS) (:$&30.);

cards;

TOTAL RECORDS              3,329

TOTAL RECORDS ACCEPTED    3,089

TOTAL RECORDS REJECTED     240

;

data want (drop=_Smiley Happy;

   set have end=last;

   _c=input(lag(totals),comma7.);

   output;

   if last then do;

      totals=catx('/', totals,_c);

      promotion='Ratio';

      output;

    end;

run;

proc print;run;

Regards,

Haikuo

Super Contributor
Posts: 349

Re: Division on obseravations

Hi,

Try this...

data have;

input PROMOTION $25. TOTALS ;

cards;

TOTAL RECORDS             3329 

TOTAL RECORDS ACCEPTED    3089

TOTAL RECORDS REJECTED     240

;

proc transpose data=have out=test;

id promotion;

var totals;

run;

data final;

set test;

Ratio=TOTAL_RECORDS_REJECTED/TOTAL_RECORDS_ACCEPTED;

run;

proc transpose data=final out=tt;

run;

Thanks,

Shiva

Ask a Question
Discussion stats
  • 3 replies
  • 247 views
  • 0 likes
  • 4 in conversation