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
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.
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
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;
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 ?
thanks again
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.
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).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.