Hi:
Here's one last example that uses both an ARRAY and a DO loop in the program:
Notice that COST1-COST3 and PRICE1-PRICE3 are available for each PARTNUM. I need to calculate some new variables called PROF1-PROF3. The calculation will be:
PROF variable value = PRICE variable value - COST variable value;
But, if I declare a "MAKECOST" array to have COST1-COST3 as members; and I declare a "SELLFOR" array to have PRICE1-PRICE3 as members, then I can create 3 new variables, PROF1-PROF3 as shown below:
The BALANCE array is declared to have PROF1-PROF3 as members. One of the neat things about ARRAYs in SAS is that if the member names do not exist, SAS will create them in the Program Data Vector (PDV). So, PROF1-PROF3 are created inside the DO loop using the ARRAY references to point to each variable. But the variable names in the output data set WIDGETS are PARTNUM, COST1-COST3, PRICE1-PRICE3 and PROF1-PROF3.
However, if I do NOT list any variables on the ARRAY statement, as shown in the program below (using SAME data as previous program):
then SAS will make me 3 numbered variables named BALANCE1, BALANCE2 and BALANCE3.
Hope this helps,
Cynthia
... View more