Maybe there are some economical or statistical procedures that I'm not familiar with.
You can use the same logic as in computing the maxATQ in order to calculate the standard deviation
using its formula which I dont remeber exactly, that is something like:
- retain sum_x - sum of variable x
sum_sqr_x - sum the squares of variable x
- then compute the STD using those sums retained and _N_ as cumulative number of observations
If you have one observation per qurter then just output each with the last computed values.
if you want comulative per whole years - output it on last.year - as in my post for maxATQ.
For each GVKEY you want maximum ATQ for the entire history of the company through the current DATADATE. Since you are using ATQ, you must be using Compustat quarterly data, correct?
Your data is probably already sorted by gvkey/datadate. If so, then
data want;
set practice;
by gvkey datadate;
retain max_atq;
if first.gvkey then max_atq=atq;
else max_atq=max(max_atq,atq);
run;
I use "by gvkey datadate", even though I only need "by gvkey". I threw in the datadate variable just to obligate SAS to report if data are out of order.
For almost all of your results, the DATADATEs within a gvkey will be separated by exactly 3 months, based on whatever month the company uses to end its fiscal year. HOWEVER, you can sometimes get shorter intervals, when a company changes its fiscal year.
The mean can be calculated by keeping track of the sum and N, accumulating as you go. In similar fashion, standard deviation can be written as a function of N, sum, and sum of squared values. If you accumulate all three pieces, you can use the same approach and calculate standard deviation at each point along the way.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.