Retaining current value for next 10 days

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Retaining current value for next 10 days

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.


Accepted Solutions
Solution
‎05-03-2016 10:18 AM
Super User
Posts: 10,028

Re: Retaining current value for next 10 days

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;

View solution in original post


All Replies
Solution
‎05-03-2016 10:18 AM
Super User
Posts: 10,028

Re: Retaining current value for next 10 days

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;
Contributor
Posts: 28

Re: Retaining current value for next 10 days

[ Edited ]

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!!!

Contributor
Posts: 28

Re: Retaining current value for next 10 days

Thanks for your logic. It works fine with little modifications.
Contributor
Posts: 28

Re: Retaining current value for next 10 days

[ Edited ]

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 422 views
  • 1 like
  • 2 in conversation