Hi Friends, Good day!!!
I need to create a new variable called Signal and populate either '+' or '-' or '0'. The condition is, if ROC>HH then '+' and no prior '-' signals for past 50 days. Likewise, if ROC<LL then '-' and no prior '+' signal for past 50 days. ROC, HH and LL are separate variables and have numeric values.
My query is, signal is the variable we are populating, how can we check whether there is prior + or - signs. How should I understand this logic and start coding?
Is it ok to populate + and - using the 1st condition, ROC>HH or ROC<LL and then consider the second condition for every observation?
in brief, we have multiple stocks and each stock has historical dates to current date. for every observation, we have ROC from 22nd observation since it is ROC for N=22 periods, HH AND LL populated from 72nd observation as they are N=50 for ROC(22).
kindly guide to populate signals.
I have also attached 1 stock information from our dataset for clear understanding.
I tried to translate your requirement into a data step:
data want;
retain lastH lastL;
set HL; by symbol;
if first.symbol then do;
lastH = '01JAN1900'd;
lastL = '01JAN1900'd;
end;
if missing(ROC) then signal = " ";
else if ROC > HH and intck("DAY", lastL, date) > 50 then do;
signal = "+";
lastH = date;
end;
else if ROC < LL and intck("DAY", lastH, date) > 50 then do;
signal = "-";
lastL = date;
end;
else signal = "0";
run;
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.
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.