BookmarkSubscribeRSS Feed
Reeza
Super User
That shouldn't matter with the code I provided. If you seem to think it does, then I clearly don't understand your problem. Please show what the input data looks like, what you want and what you've tried. I'd rather you took the time to fully explain the problem in detail, your responses so far are very brief and do not allow us to understand your problem.
jimbarbour
Meteorite | Level 14

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:

jimbarbour_0-1600716265930.png

 

Jim

Kurt_Bremser
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 2697 views
  • 2 likes
  • 6 in conversation