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.
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!
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.