1.May I know why Variable 'last.breakhigh'n is uninitialized?
2.How may I solve MERGE statement has more than one data set with repeats of BY values?
Thx!!
DM'LOG; CLEAR; OUT; CLEAR; ODSRESULTS; CLEAR;';
%let folder=%str(C:\Users\SC\Desktop\HIGH);
LIBNAME HIGH "&folder";
DATA CRSP;
SET HIGH.DAILY;
RUN;
DATA CRSP;
SET CRSP;
PRC=ABS(PRC);
IF SHRCD^=10 AND SHRCD^=11 THEN DELETE;
IF RET=-66 THEN RET=.;
IF RET=-77 THEN RET=.;
IF RET=-88 THEN RET=.;
IF RET=-99 THEN RET=.;
KEEP PERMNO DATE PRC RET;
RUN;
PROC SORT DATA= CRSP;
BY PERMNO DATE;
RUN;
data highs;
set CRSP;
by PERMNO date;
retain highest 0;
if first.PERMNO then highest = PRC;
else highest = max(highest, PRC);
if PRC > highest then do;
BREAKHIGH = 1;
six_months_later = intnx('month', date, 6, 'same');
end;
else BREAKHIGH = 0;
if BREAKHIGH = 1 then last_break_date = date;
else if last.breakhigh then last_break_date = .;
run;
data Returns;
merge highs(in=a) CRSP(in=b rename=(date=date_future PRC=PRC_future));
by PERMNO;
if a and b and intck('month', last_break_date, date_future) = 6 then do;
six_month_return = (PRC_future - PRC) / PRC;
end;
run;
You can't use LAST.Breakhigh because it isn't established yet in the code. In other words, it does not exist in your CSRP data set. The variable exists in HIGHS, so you would need to use FIRST/LAST on the next data set you create. This comes down to how the PDV works.
FIRST/LAST processing can occur when the variable exists on the input data set, you have sorted it by the desired variables, and you include it on the BY statement after the SET statement.
Also, please provide usable data for us. You can use the data to data step macro.
You can't use LAST.Breakhigh because it isn't established yet in the code. In other words, it does not exist in your CSRP data set. The variable exists in HIGHS, so you would need to use FIRST/LAST on the next data set you create. This comes down to how the PDV works.
FIRST/LAST processing can occur when the variable exists on the input data set, you have sorted it by the desired variables, and you include it on the BY statement after the SET statement.
Also, please provide usable data for us. You can use the data to data step macro.
Thank you for your reply, data to data step macro seem hard to me to understand how to create, sry.
May I further know how to define last.breakhigh would be ok?
I put short version data via google, is it easier for help? Thx a lot!
https://drive.google.com/file/d/1ayhUMgH0j2IuIykNpgUt6WbPg-7Gx-JA/view
There are a number of issues with your management of the CRSP data, some minor, some major. Here's a couple:
data highs;
set CRSP;
by PERMNO date;
retain highest 0;
if first.PERMNO then highest = PRC;
else highest = max(highest, PRC);
if PRC > highest then do;
BREAKHIGH = 1;
six_months_later = intnx('month', date, 6, 'same');
end;
else BREAKHIGH = 0;
if BREAKHIGH = 1 then last_break_date = date;
else if last.breakhigh then last_break_date = .;
run;
Since you set PRC to max(highest,PRC) prior to your "if PRC > highest then do;" statement, the if test is never true. And breakthrough will never take the value of 1, nor will you ever assign a value to six_months_later.
So here are some questions:
if BREAKHIGH = 1 then last_break_date = date;
else if last.breakhigh then last_break_date = .;
Finaly please provide an example of what you want the OUTPUT to look like. I can't tell whether you need dataset HIGHs to only have breakthrough=1 obs, or needs to have all obs.
Thank you for your reply!
yes, breakthrough high means "highest PRC so far",
I want to compare PRC to the highest PRECEDING PRC,and divide into 2 group.
and run the excess return by 3 factor model by this two group.
the first obs be a breakthrough high should be after one year.
What the output I want to produce is as below, instead of by breakthough 52-weeks high, but by historical high. Thx!!
Thank you!
I want SAS program that define the highest historical prices of each stock from 1963 to 2023, and create a new variable BREAKHIGH to represent when the closing price breaks through the historical high. After breaking through the historical high, calculate the six-month return of that stock. I want to divide into 2 group by breakthrough historical high and the rest,and run the excess return by 3/4/5 factor model by this two group.
the first obs be a breakthrough high should be after one year historical data.
More comments:
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.