Hi,
I am trying to get the change in the rate for each country, by using Table 1 as an example,
CTRY_CODE | year | Corporate_Tax_Rates | (calculate method) | Actual_change_in_tax_rate |
AU | 1990 | 0.39 | ||
AU | 1991 | 0.38 | 0.38-0.39 | -0.01 |
AU | 1992 | 0.39 | 0.39-0.38 | 0.01 |
AU | 1993 | 0.33 | 0.33-0.39 | -0.06 |
AU | 1994 | 0.33 | 0.33-0.33 | 0 |
AT | 1990 | 0.3 | ||
AT | 1991 | 0.3 | 0.3-0.3 | 0 |
AT | 1992 | 0.6 | 0.6-0.3 | 0.3 |
AT | 1993 | 0.3 | 0.3-0.6 | -0.3 |
AT | 1994 | 0.34 | 0.34-0.3 | 0.04 |
I expect to get the 'Actual_change_in_tax_rate' variable. In the second row, the -0.01 equals 0.38 (i.e., Corporate_Tax_Rate of AU in 1991) - 0.39 (i.e., Corporate_Tax_Rate of AU in 1990).
Could you please give me some suggestions about this.
thanks in advance.
data table1; infile cards dsd dlm=","; input CTRY_CODE :$2. year :8. Corporate_Tax_Rates :8. ; cards; AU,1990,0.39 AU,1991,0.38 AU,1992,0.39 AU,1993,0.33 AU,1994,0.33 AT,1990,0.3 AT,1991,0.3 AT,1992,0.3 AT,1993,0.3 AT,1994,0.34 ;;;; run;
data table1;
infile cards dsd dlm=",";
input
CTRY_CODE :$2.
year :8.
Corporate_Tax_Rates :8.
;
cards;
AU,1990,0.39
AU,1991,0.38
AU,1992,0.39
AU,1993,0.33
AU,1994,0.33
AT,1990,0.3
AT,1991,0.3
AT,1992,0.6
AT,1993,0.3
AT,1994,0.34
;;;;
run;
data want;
set table1;
by ctry_code notsorted;
Actual_change_in_tax_rate=dif(Corporate_Tax_Rates);
if first.ctry_code then Actual_change_in_tax_rate=.;
run;
Hi @Alexxxxxxx Ideally, your source dataset should be sorted by ctry_code year for the reason the rate of change is computed across the years in sequence for a ctry_code. Since your dataset isn't sorted, I used NOTSORTED option in the BY statement. However I am of the understanding that is trivial and you would take care of that. Just FYI- had your dataset been sorted by ctry_code year, there wouldn't be a need for NOTSORTED.
data table1;
infile cards dsd dlm=",";
input
CTRY_CODE :$2.
year :8.
Corporate_Tax_Rates :8.
;
cards;
AU,1990,0.39
AU,1991,0.38
AU,1992,0.39
AU,1993,0.33
AU,1994,0.33
AT,1990,0.3
AT,1991,0.3
AT,1992,0.6
AT,1993,0.3
AT,1994,0.34
;;;;
run;
data want;
set table1;
by ctry_code notsorted;
Actual_change_in_tax_rate=dif(Corporate_Tax_Rates);
if first.ctry_code then Actual_change_in_tax_rate=.;
run;
Hi @Alexxxxxxx Ideally, your source dataset should be sorted by ctry_code year for the reason the rate of change is computed across the years in sequence for a ctry_code. Since your dataset isn't sorted, I used NOTSORTED option in the BY statement. However I am of the understanding that is trivial and you would take care of that. Just FYI- had your dataset been sorted by ctry_code year, there wouldn't be a need for NOTSORTED.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.