BookmarkSubscribeRSS Feed
raqthesolid
Quartz | Level 8

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

6 REPLIES 6
Reeza
Super User

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. 

raqthesolid
Quartz | Level 8

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 

Reeza
Super User

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;
raqthesolid
Quartz | Level 8

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

Reeza
Super User

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. 

 

 

ballardw
Super User

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 9600 views
  • 2 likes
  • 3 in conversation