09-25-2016 10:48 AM
Hello Everyone i am new to sas so fighting long to do a thing which may be simple to you. Kindly help me in this regards
i have just four variables,
PerMNO is firm identifier
Names Date = date (there are 10 years from 2004 to 2014 which i am interested.)
Returns = monthly returns
Mrktcapt = market capitalization
What i have am trying to do :
1) organize this data in decile on the basis of Marktcapt
2) find the mean return and standard deviation of return in each year.
i have attached a data file and the second sheet in this excel file show a sample for what i am trying to do.
Please give help me with some codes which can do this thing.
Thanks a lot
09-25-2016 12:05 PM
1. Use Proc Rank with group=10 if you want deciles.
2. Look at Proc means to generate summary statistics. If you need summary statistic by group look at the CLASS or BY statement in Proc means.
09-25-2016 01:13 PM - last edited on 09-25-2016 01:35 PM by Reeza
i tried Proc Rank codes
proc rank data=apt.nyse out=rnyse groups=10; by mrktcapt; var returns; run;
but i don't think it is right. it converted my returns into groups (1-10) but i want them to be as they are and groups of "Mrktcapt" and plus i want their ranking in each year but i am not able to do it .
kindly write some line of codes. thanks
09-25-2016 01:37 PM
Your grouping variable goes into your BY statement.
The var you want the deciles based on goes in your VAR statement.
Add a RANK statement to store your Ranks
proc rank data=apt.nyse out=rnyse groups=10; by Year; var mrktcap; rank rank_mrkt_cap; run;
09-25-2016 02:20 PM
THanks Reeza this code worked.
there is another issue . in my data i have two variables Month and year, i want to define a year which start from July and End with june , how can i do this ?
09-25-2016 03:36 PM
You have to recode this to create a new variable that will resolve to your year of interest.
Or use a custom format, possibly look at multilabel format.
I'd probably create a new variable using if/then code.
09-26-2016 11:03 AM
First step when involving date manipulation is often to make sure you have a SAS date value. If you currently have month and year as numeric values then in a datat step:
SasDate = mdy(month,1,year);
creates a date that represents the first day of the month.
Then a "modified" year such as you have can be made as:
NewYearVar = Year(SasDate) + (month(SASDate) ge 7);
These two lines should be in the same data step. Pick your own names for SasDate and NewYearVar.
(Looks like a State Fiscal Year to me).