data have; input contype$1-3 TimeStamp CP PP MM; informat TimeStamp date9.; format TimeStamp date9.; cards; PMC 31May2024 200 200 200 PMC 28JUN2024 235 244 33 PMC 31JUL2024 235 500 654 PMC 30SEP2024 238 234 222 ERC 31JAN2023 109 546 230 ERC 28FEB2023 234 320 777 ERC 31MAR2023 223 111 435 ERC 29SEP2023 187 325 120 PCP 31JAN2023 200 200 200 PCP 28FEB2023 235 244 33 PCP 31MAR2023 235 500 654 PCP 29SEP2023 238 234 222 PCP 29DEC2028 109 546 230 PCP 31DEC2034 234 320 777 ; run; proc sort data=have; by contype; run; data dates; input enddate date9.; informat enddate date9.; format enddate date9.; cards; 30JUL2022 31JAN2023 28FEB2023 31MAR2023 29SEP2023 31May2024 28JUN2024 31JUL2023 31JAN2024 31JUL2024 30SEP2024 31OCT2024 29NOV2024 28FEB2025 31MAR2027 31AUG2028 29DEC2028 ; run; proc summary data=dates ; var enddate; output out=lastday max=enddate; run; data want; if _n_=1 then set lastday(keep=enddate); set have; by contype; output; if last.contype then do; cp=0; pp=0; mm=0; do date=date+1 to enddate; output; end; end; run; I ran this code but i get below error ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or invalid. enddate=29DEC2028 contype=ERC TimeStamp=29SEP2023 CP=0 PP=0 MM=0 FIRST.contype=0 LAST.contype=1 date=. _ERROR_=1 _N_=4 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 96:17 NOTE: The SAS System stopped processing this step because of errors. NOTE: There were 1 observations read from the data set WORK.LASTDAY. NOTE: There were 5 observations read from the data set WORK.HAVE. WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 4 observations and 7 variables. WARNING: Data set WORK.WANT was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds Output is coming looking like this enddate ConType TimeStamp CP PP MM date 29-Dec-28 PMC 31-May-24 200 200 200 . 29-Dec-28 PMC 28-Jun-24 235 244 33 . 29-Dec-28 PMC 31-Jul-24 235 500 654 . But i need output like this For PMC the end date is 30SEP2024 and i need to extend the records until 2028 but the dates after 30sep 2024 i will take from Test2 take 31oct2024,29nov2024 ,28feb2025 all these dates are found in test2 and then cp,pp,mm will be zero for those extended dates PMC 31OCT2024:00:00:00 0 0 0 PMC 29NOV2024:00:00:00 0 0 0 PMC 28FEB2025:00:00:00 0 0 0 PMC 31MAR2027:00:00:00 0 0 0 PMC 31AUG2028:00:00:00 0 0 0 PMC 29DEC2028:00:00:00 0 0 0 ConType TimeStamp CP PP MM PMC 31May2024:00:00:00 200 200 200 PMC 28JUN2024:00:00:00 235 244 33 PMC 31JUL2024:00:00:00 235 500 654 PMC 30SEP2024:00:00:00 238 234 222 PMC 31OCT2024:00:00:00 0 0 0 PMC 29NOV2024:00:00:00 0 0 0 PMC 28FEB2025:00:00:00 0 0 0 PMC 31MAR2027:00:00:00 0 0 0 PMC 31AUG2028:00:00:00 0 0 0 PMC 29DEC2028:00:00:00 0 0 0 ERC 31JAN2023:00:00:00 109 546 230 ERC 28FEB2023:00:00:00 234 320 777 ERC 31MAR2023:00:00:00 223 111 435 ERC 29SEP2023:00:00:00 187 325 120 ERC 31May2024:00:00:00 0 0 0 ERC 28JUN2024:00:00:00 0 0 0 ERC 31JUL2023:00:00:00 0 0 0 ERC 31JAN2024:00:00:00 0 0 0 ERC 31JUL2024:00:00:00 0 0 0 ERC 30SEP2024:00:00:00 0 0 0 ERC 31OCT2024:00:00:00 0 0 0 ERC 29NOV2024:00:00:00 0 0 0 ERC 28FEB2025:00:00:00 0 0 0 ERC 31MAR2027:00:00:00 0 0 0 ERC 31AUG2028:00:00:00 0 0 0 ERC 29DEC2028:00:00:00 0 0 0 PCP 31JAN2023:00:00:00 200 200 200 PCP 28FEB2023:00:00:00 235 244 33 PCP 31MAR2023:00:00:00 235 500 654 PCP 29SEP2023:00:00:00 238 234 222 PCP 29DEC2028:00:00:00 109 546 230 PCP 31DEC2034:00::00 234 320 777
... View more