Quartz | Level 8

## Standard Deviation and Rank Transformation

Hello SAS Support Communities,

I have attached dataset comp16f.  Please send me a code I can use to do the following:
1. Standard deviation of ib1 for three years at a time.  Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.
2. Rank transform the variable created in step 1 between 0 and 1.

God bless, best regards, and take care,
1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: Standard Deviation and Rank Transformation

Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.

I cannot open your zip file with the data, so I am going by the description of the data you stated and which I have quoted above. PROC EXPAND would work if you have each value of the three years in separate rows. But you state that the values you need are included for each observation. Thus, you need the STD function. Something like:

``_3year_std = std(lb1,lag1,lag2);``
--
Paige Miller
6 REPLIES 6
Diamond | Level 26

## Re: Standard Deviation and Rank Transformation

Instead of asking for code, you need to try to do this yourself, and if you can't get it, post your code so we can help you fix it.

Standard deviations are simple to compute in SAS, using data step or PROC SUMARY; and rank transformations can be done with PROC RANK.

--
Paige Miller
Quartz | Level 8

## Re: Standard Deviation and Rank Transformation

Hi Paige,

Thank you for your response.  I tried the following code:

PROC EXPAND DATA=dissert1.comp16f OUT=dissert1.comp16g;
CONVERT ib1=std / TRANSFORMOUT=(MOVSTD 3);
by gvkey;
RUN;

I would expect results to only show for firms that have a minimum of three observations.  However, there are values for firms with two observations.  What do you think?

God bless, best regards, and take care,

Diamond | Level 26

## Re: Standard Deviation and Rank Transformation

Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.

I cannot open your zip file with the data, so I am going by the description of the data you stated and which I have quoted above. PROC EXPAND would work if you have each value of the three years in separate rows. But you state that the values you need are included for each observation. Thus, you need the STD function. Something like:

``_3year_std = std(lb1,lag1,lag2);``
--
Paige Miller
Quartz | Level 8

## Re: Standard Deviation and Rank Transformation

Thank you again Paige!

I got the same answer with the following three codes:

PROC EXPAND DATA=dissert1.comp16f OUT=dissert1.comp16h;
CONVERT ib1=std / TRANSFORMOUT=(MOVSTD 3);
by gvkey;
RUN;

proc sql;
create table dissert1.comp16g as
select *,(select std(ib1) from dissert1.comp16f where fyear between a.fyear-2 and a.fyear and gvkey=a.gvkey) as rolling_std
from dissert1.comp16g as a;
quit;

data dissert1.comp16f1;
set dissert1.comp16f;
_3year_std = std(ib1,lag1,lag2);
run;

For proc rank, I did the following:

proc rank data=dissert1.comp16g out=dissert1.comp16h;
var _3year_std;
ranks Finish;
run;

How would I convert the finish variable from 0 to 1?

Diamond | Level 26

## Re: Standard Deviation and Rank Transformation

In PROC RANK, use the GROUPS=100 option. This gives numbers on the 0 to 100 scale.

--
Paige Miller
Quartz | Level 8

## Re: Standard Deviation and Rank Transformation

Great job Paige!  Thank you so much for your help!  God bless you and your family!