BookmarkSubscribeRSS Feed
Hima
Obsidian | Level 7

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

3 REPLIES 3
Reeza
Super User

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;

Haikuo
Onyx | Level 15

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=_:);

   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

shivas
Pyrite | Level 9

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

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
  • 3 replies
  • 578 views
  • 0 likes
  • 4 in conversation