BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexxxxxxx
Pyrite | Level 9

Hi, 

 

I am trying to get the change in the rate for each country, by using Table 1 as an example,

 

CTRY_CODEyearCorporate_Tax_Rates(calculate method)  Actual_change_in_tax_rate
AU19900.39  
AU19910.380.38-0.39-0.01
AU19920.390.39-0.380.01
AU19930.330.33-0.39-0.06
AU19940.330.33-0.330
AT19900.3  
AT19910.30.3-0.30
AT19920.60.6-0.30.3
AT19930.30.3-0.6-0.3
AT19940.340.34-0.30.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;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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.

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 511 views
  • 1 like
  • 2 in conversation