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

Sorry

 

It is here

Ksharp
Super User
data table1;
   length
      product $ 1
      st_date end_date 8
      price 8
   ;

   informat st_date end_date date.;
   format st_date end_date date9.;
   input product st_date end_date price;

   datalines;
A 01-Jan-18 06-Jan-18 10
B 09-Feb-18 14-Feb-18 20
C 06-May-18 11-May-18 30
D 11-Jun-18 16-Jun-18 15
;
run;

data table2;
   length
      product $ 1
      override_date 8
      price 8
   ;

   informat override_date date.;
   format override_date date9.;
   input product override_date price;

   datalines;
A 03-Jan-18 12
B 09-Feb-18 18
D 17-Jun-18 23
;
run;
data temp;
 set table1;
 n+1;
 do date=st_date to end_date;
  output;
 end;
 format date date9.;
 drop st_date end_date;
run;
data temp1;
 merge temp table2(in=inb rename=(price=_price override_date=date));
 by product date;
 in_b=inb;
run;
data temp2;
 set temp1;
 if n ne lag(n) or in_b then group+1;
run;
proc sql;
create table want as
select group,max(Product) as Product,
 min(date) as st_date format=date9.,
 max(date) as end_date format=date9.,
 coalesce(max(_price),max(price)) as Price
 from temp2
  group by group;
quit;
Srigyan
Quartz | Level 8

Hi,

Thanks, this answer also worked for me. But i could have select only one answer as solution so I accepted the first one. But this answer work fine for me. Thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 17 replies
  • 2631 views
  • 3 likes
  • 5 in conversation