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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 863 views
  • 1 like
  • 3 in conversation