Hello friends,
First of all, Thanks a lot!!! I have been getting wonderful response and solutions from members of this group.
I have a query,
Please find my attached excel file, It has values for CE1, CE2, CE3, CE4, CE5. The requirement is, if CE4 = "+" then trigger Trend="UP" for next 10 days. whenever we encounter CE4="+" then we should trigger "UP" trend for next 10 days. Please someone guide me how to achieve this in SAS?
Thanks in advance.
What current value you want to retain ? You also want operate it in each SYMBOL group ?
proc import datafile='/folders/myfolders/ce12345.xlsx' dbms=xlsx replace out=have;run;
data want;
set have;
by symbol;
retain new_close _date;
if first.symbol then call missing(new_close,_date);
if ce4='+' then do;
new_close=close;
_date=date1;
end;
if date1 gt sum(_date,10) then call missing(new_close);
drop _date;
run;
What current value you want to retain ? You also want operate it in each SYMBOL group ?
proc import datafile='/folders/myfolders/ce12345.xlsx' dbms=xlsx replace out=have;run;
data want;
set have;
by symbol;
retain new_close _date;
if first.symbol then call missing(new_close,_date);
if ce4='+' then do;
new_close=close;
_date=date1;
end;
if date1 gt sum(_date,10) then call missing(new_close);
drop _date;
run;
Ksharp, Thanks a lot for your guidance. I need to retain the current "UP" value for the Trend column we are creating for the next 10 days whenever we encounter a "+" in the CE4 variable. And yes, for each symbol group. Just saw your answer. I will apply and test in my coding. Thanks!!!
I have found a solution .Hope this works.
data inter;
set ce12345;
length trend $8.;
retain hhcnt;
if ce4="+" then do;
tr="UP4";
hhcnt=count;
end;
if hhcnt ne . and (count-hhcnt)<= 9 then tr="UP";
run;
Please confirm.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.