Hello,
I have tuition fees laid out for 4 years (Variables Fee_YR_01-Fee_YR_04
) starting current year (Fee_YR_01
). Variables Increase_YR_01-Increase_YR_04
in the sample dataset shows the proposed tuition fee increase rate (in percent) based on the previous year. I want to calculate the future tuition based on this proposed tuition increase rate (in the new variables Fee_New_YR_02 - Fee_New_YR_04). I want a dynamic solution for this calculation. Thank you all.
My data set looks like this:
data have;
input Fee_YR_01 Fee_YR_02 Fee_YR_03 Fee_YR_04 Increase_YR_01 Increase_YR_02 Increase_YR_03 Increase_YR_04;
datalines;
1000 1050 1100 1150 0 20 20 20
1000 1070 1100 1150 0 20 20 20
3000 3100 3150 3200 0 15 15 15
3000 3200 3200 3300 0 15 15 15
4000 4150 4200 4250 0 15 15 15
4000 4200 4300 4350 0 15 15 15
;
RUN;
This is the output I want:
Fee_New_YR_02 | Fee_New_YR_03 | Fee_New_YR_04 |
1200 | 1260 | 1320 |
1200 | 1284 | 1320 |
3450 | 3565 | 3622.5 |
3450 | 3680 | 3680 |
4600 | 4772.5 | 4830 |
4600 | 4830 | 4945 |
Calculations: Fee_New_YR_02=Fee_YR_01 * 1.2 (increased by 20%)
I have shown you a small set of data. But I have 150 variables for tuition fees and 150 variables for the tuition rate increase. So I need help on how to do it dynamically.
You will need to three use arrays:
the a simple loop and the job is almost done.
Have a look at the docs of the array statement, to get the details.
EDIT: Forgot to add a hint about improving the data structure, so here it is: the calculation would be easier if your dataset would not have data in the names of variables (YR_01 ...), but a variable holding the value of the year. With that structure the calculation would look like
data want;
set have;
new_fee = fee * (1 + Increase / 100);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.