BookmarkSubscribeRSS Feed
zilong567
Calcite | Level 5

I use the method group by to obtain stock volitality from crsp daily stock file. But my problem is that the observations go from 36 thousand to more than 1 billion. And there are many same results, with same lpermno, same fyear and same lstkvol. I couldn't find the reason. Thanks!

proc sql;
create table exe_ccn_lancmpcrsp as
select a.*,std(b.RET)*sqrt(250) as lstkvol "lag annualized stock volitality"
from exe_ccn_lancmpllq a left join crspa.DSF b
on a.lpermno=b.permno and b.DATE between a.lfybegdt and a.lfyenddt
group by a.lpermno,a.fyear
having sum(b.RET is not missing)>1;
quit;

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

I don't understand your problem? Please elaborate.

FreelanceReinh
Jade | Level 19

@zilong567 wrote:

But my problem is that the observations go from 36 thousand to more than 1 billion. And there are many same results, with same lpermno, same fyear and same lstkvol. I couldn't find the reason. 


 

I take it that your dataset A has about 36000 observations, but you are wondering why the table resulting from this left join consists of >1 billion observations and that this is mainly due to duplicate observations ("same results, with same lpermno, ...").

 

The reason is that "The query requires remerging summary statistics back with the original data." -- as the SAS log must have told you. To avoid the duplicates, you can either insert the keyword distinct after "select" or – better – extend the group by clause by all other variables from A (in particular a.lfybegdt, a.lfyenddt). The advantage of extending the group by clause is that remerging does not occur (see SAS log), which reduces run time.

PGStats
Opal | Level 21

To add to @FreelanceReinh's excellent suggestion...

 

Why a left join with the having condition sum(b.RET is not missing)>1. Table exe_ccn_lancmpllq records without a match in crspa.DSF will have all RET values missing, so they will be dropped by the having condition. You might as well use an inner join.

PG

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!

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
  • 3 replies
  • 673 views
  • 0 likes
  • 4 in conversation