Can you post your actual data? The contents of M1_000? Is it always very carefully formatted?
@Kurt_Bremser has a good point that SAS dates are generally the best way to work with dates (instead of plain text). If you convert to SAS dates, you could write:
DATA M1_000;
DROP Temp_String Temp_Date;
FORMAT Date1 YYMMDD10.;
INFILE DATALINES4;
LENGTH Temp_String $11;
INPUT Temp_String $;
Temp_Date = CATS(SUBSTR(Temp_String, 1, 7), '-01');
Date1 = INPUT(Temp_Date, YYMMDD10.);
DATALINES4;
2019-01-Jan
2019-02-Feb
2019-03-Mar
2019-04-Apr
2019-12-Dec
2020-01-Jan
2020-02-Feb
2020-03-Mar
2020-04-Apr
2020-12-Dec
;;;;
RUN;
DATA M_000;
SET M1_000;
LENGTH Date2 $7;
Date2 = PUT(Date1, YYMMD7.);
RUN;
Results:
Jim
@Son_Sam wrote:
Can you please provide me the code
Quote from myself:
"So the first thing you do is fix the process that creates these strings."
Show the code that creates these strings.
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.