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.
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;
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.