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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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