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

 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
Lapis Lazuli | Level 10
Wonderful anwser.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 415 views
  • 1 like
  • 2 in conversation