ArtemShch
6/19/2018 - 9:17 AM

Perl regular Swap

Perl regular Swap

data SwitchDates(keep=OldDateString NewDateString);
 
  mdy_exp="/(\d{1,2})[\/-](\d{1,2})[\/-](\d{4})/";
  /* 1-2 digits,dash or slash,1-2 digits,dash or slash,4 digits */
  date_exp="/(\d{1,2})(\w{3})(\d{4})/";
  /* 1-2 digits,3 letters,4 digits */
  if prxmatch("/\d{4}[\/-]\d{1,2}[\/-]\d{1,2}/",OldDateString)
  /* 4 digits,dash or slash,1-2 digits,dash or slash,1-2 digits */
  then NewDateString=OldDateString;
  else if prxmatch(mdy_exp,OldDateString)
  then NewDateString=prxchange("s"||mdy_exp||"$3-$1-$2/",
  1, OldDateString);
  else if prxmatch(date_exp,OldDateString)
  then NewDateString=prxchange("s"||date_exp||"$2 $1, $3/",
  1, OldDateString);
  else NewDateString=" ";
run;