BookmarkSubscribeRSS Feed
Srigyan
Quartz | Level 8

I have a table

 

Product_IDstarting Dateprice
ID101-Jan-187
ID105-Jan-1889
ID107-Jan-186

 

I want to write the code to generate below data point

 

Product_IDstarting Dateprice
ID101-Jan-187
ID102-Jan-187
ID103-Jan-187
ID104-Jan-187
ID105-Jan-1889
ID106-Jan-1889
ID107-Jan-186
2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

 

As such not tested:

data want;
  set have;
  by product_id;
  retain lstdt;
  if first.product_id then lstdt=starting_date;
  else do;
    do i=1 to starting_date-lstdt;
      output;
      starting_date=starting_date+i;
    end;
  end;
run;

  
Ksharp
Super User
data have;
infile cards expandtabs truncover;
input Product_ID $	startingDate : date11. price;
format startingDate date9.;
cards;
ID1	01-Jan-18	7
ID1	05-Jan-18	89
ID1	07-Jan-18	6
;
run;
data want;
 merge have have(keep=Product_ID startingDate
 rename=(Product_ID=_p startingDate=_s) firstobs=2);
output;
if Product_ID=_p then do;
  do i=startingDate+1 to _s-1;
    startingDate=i;output;
  end;
end;
drop i _p _s;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1120 views
  • 1 like
  • 3 in conversation