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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.