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

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.
 
Thank you so much in advance for your help!
 
God bless, best regards, and take care,
Jadallah
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

 

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

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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
jjadall1
Quartz | Level 8

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,

Jadallah 

PaigeMiller
Diamond | Level 26

 

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
jjadall1
Quartz | Level 8

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?

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
jjadall1
Quartz | Level 8

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

Jadallah

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1808 views
  • 0 likes
  • 2 in conversation