Calculating deltas (changes) of variables

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Calculating deltas (changes) of variables

Hi everyone,

 

I have two of what I assume are basic questions. 

 

1. I'm required to calculate the delta of variables i.e the changes in the variables from one fiscal year to the other. May I know the best way to handle this?

 

2. With other Softwares, like stata, there is a function one can use to indicate that their data is a panel one. My question: Is a there a function like that in SAS and does it matter if it is not indicated to SAS that the data is a panel one?

 

Thank you very much and I look forward from hearing from you.


Accepted Solutions
Solution
3 weeks ago
Esteemed Advisor
Posts: 7,293

Re: Calculating deltas (changes) of variables

Does the following reflect what you want to accomplish?:

data have;
  input fiscal_year  x;
  cards;
2000                5
2001                3
2002                .
2003                1 
2004                3
2005                2
;

data want;
  set have;
  delta=x/lag(x)-1;
run;

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Grand Advisor
Posts: 9,576

Re: Calculating deltas (changes) of variables

[ Edited ]

Here is an example to show you how to get fiscal year ( start from  01july).

 

data have;
do date='01jan2010'd to '01jan2014'd;
 do stock=1 to 10;
  ret=rand('normal');
  ret1=rand('normal');
  output;
 end;
end;
format date date9.;
run;

data have;
 set have;
 year=year(intnx('year.7',date,0,'b'));
run;   

proc sort data=have;
 by  stock year;
run;
Contributor
Posts: 33

Re: Calculating deltas (changes) of variables

Dear KSharp,

 Thank you for the reply.

 

Actually, I'm not trying to get a fiscal year. I rather want to calculate the delta(change) of variables from one fiscal year to the other.

Eg.

fiscal year             variable(x)

2000                5

2001                3

2002                .

2003                1 

2004                3

2005                2

 

How to you calculate the delta(changes) in x for each of the fiscal years?

Thanks

 

Solution
3 weeks ago
Esteemed Advisor
Posts: 7,293

Re: Calculating deltas (changes) of variables

Does the following reflect what you want to accomplish?:

data have;
  input fiscal_year  x;
  cards;
2000                5
2001                3
2002                .
2003                1 
2004                3
2005                2
;

data want;
  set have;
  delta=x/lag(x)-1;
run;

Art, CEO, AnalystFinder.com

Contributor
Posts: 33

Re: Calculating deltas (changes) of variables

I think that'll do art297. I thought there was a code like it is in stata, specifically for delta.
Do you any opinion on my other question. Thanks
Esteemed Advisor
Posts: 7,293

Re: Calculating deltas (changes) of variables

SAS has a panel procedure (in SAS/ETS).

 

Other than that, proc transpose is available to make files long or wide, and one can take advantage of number of statements and functions to calculate deltas depending upon how the data is structured (e.g., using arrays, the retain statement, or the lag function).

 

Art, CEO, AnalystFinder.com

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 82 views
  • 0 likes
  • 3 in conversation