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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.