BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
whymath
Barite | Level 11

 Today, I have this bothering problem to ask for your help. Very preciate for your reading.

 

I an trying to change a datetime variable like '2020-05-18T9:27:58' to its regular form '2020-05-18T09:27:58', yes, that is the E8601DT format. So I code some tests like below:

 

data _null_;
	DTMC = '2020-05-18T9:27:58';
	ADTMC1 = prxchange('s/(.*?T)(\d:.*)/$10$2/',1,DTMC);
	ADTMC2 = prxchange('s/(.*?T)(\d:.*)/$1 0$2/',1,DTMC);
	ADTMC3 = prxchange('s/(.*?)T(\d:.*)/$1T0$2/',1,DTMC);
	put (ADTMC:) (=/);
run;

Here is the output:

 

 

ADTMC1=9:27:58
ADTMC2=2020-05-18T 09:27:58
ADTMC3=2020-05-18T09:27:58

As you can see, Only  ADTMC3 meet the desire.

I am very sure that  $10 in the first expression is trying to catch the 10th match group, which is failed, finally. $1 0$2 in the second expression successfully catch the first and second match group and add '0' between it, with an extra space.

May I modify the first expression to have the right result? Thanks for any hints.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You only need to match the substring(s) that you want to change. In your case, it is quite simple:

 

data _null_;
	DTMC = '2020-05-18T9:27:58';
	ADTMC1 = prxchange('s/T(\d):/T0\1:/', 1, DTMC);
	put (ADTMC:) (=/);
run;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

You only need to match the substring(s) that you want to change. In your case, it is quite simple:

 

data _null_;
	DTMC = '2020-05-18T9:27:58';
	ADTMC1 = prxchange('s/T(\d):/T0\1:/', 1, DTMC);
	put (ADTMC:) (=/);
run;
PG
whymath
Barite | Level 11
Wonderful anwser.

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
  • 2 replies
  • 846 views
  • 1 like
  • 2 in conversation