BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lakshmiG
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

4 REPLIES 4
Ksharp
Super User

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;
lakshmiG
Obsidian | Level 7

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

lakshmiG
Obsidian | Level 7
Thanks for your logic. It works fine with little modifications.
lakshmiG
Obsidian | Level 7

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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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