data work.customercoupons; array cpnvalue[3,4] _temporary_ (.10, .15, .20, .25, .30, .40, .10, .15, .20, .25, .15, .10); set certadv.stcoup (keep=CustomerID OrderType Quantity); CouponValue=cpnvalue[OrderType,Quantity]; format CouponValue percent10.; run; title 'Coupons for October 2019'; proc print data=work.customercoupons; run;
data work.diffsales; array yrsales[2014:2018,4] _temporary_; /*1*/ if _N_=1 then do Yr=2014 to 2018; /*2*/ set certadv.us_sales; /*3*/ array qtrsal[4] SalesQ1-SalesQ4; /*4*/ do Qtr=1 to 4; /*5*/ yrsales[Yr,Qtr]=qtrsal[Qtr]; end; end; set certadv.us_goals; /*6*/ Sales=yrsales[Year,QtrNum]; /*7*/ Difference=Sales-Goal; /*8*/ drop Yr Qtr SalesQ1-SalesQ4; /*9*/ run; proc print data=work.diffsales; format Goal Sales Difference dollar14.2; run;
1 | The ARRAY statement defines a two-dimensional array named YrSales. The YrSales array contains five rows starting with 2014 and ending with 2018, and four columns that correspond to quarterly sales values. There are 20 elements in the YrSales array. Since the array is temporary, the elements do not appear in the output table. |
2 | The IF-THEN statement loads the YrSales array only the first time through the DATA step. The DO statement loops through enough times to read in every row of input data. |
3 | The SET statement reads in the four quarterly values from Certadv.US_Sales into the PDV. |
4 | The ARRAY statement defines a one-dimensional
array named QtrSal with four elements, SalesQ1–SalesQ4.
Note: The result is two ARRAY statements.
The first one contains 20 values, and the second one is used to read
in the quarterly sales values from the input table.
|
5 | The DO loop reads in the four quarterly sales values for each year, loading the YrSales array. |
6 | The SET statement reads in the values from Certadv.US_Goals. |
7 | A new variable named Sales is created and assigns the YrSales array to the variable. The Sales variable looks up the Sales value based on the values of Year and QtrNum. |
8 | A new variable named Difference is created. The difference between the variable Sales and Goal is calculated to determine whether the sales team met their goals each quarter for the past five years. |
9 | The DROP statement is used to drop the index variables and any other nonessential variable. |