I have a table
| Product_ID | starting Date | price |
| ID1 | 01-Jan-18 | 7 |
| ID1 | 05-Jan-18 | 89 |
| ID1 | 07-Jan-18 | 6 |
I want to write the code to generate below data point
| Product_ID | starting Date | price |
| ID1 | 01-Jan-18 | 7 |
| ID1 | 02-Jan-18 | 7 |
| ID1 | 03-Jan-18 | 7 |
| ID1 | 04-Jan-18 | 7 |
| ID1 | 05-Jan-18 | 89 |
| ID1 | 06-Jan-18 | 89 |
| ID1 | 07-Jan-18 | 6 |
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.