Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Standard Deviation and Rank Transformation

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-10-2018 12:16 PM
(2056 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Jadallah

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.