I have a variable with dates in different formats and ranges. The first one is pretty simple. Looking for a way to scan and extract text for the latest date from the other variations so that I end up with the dates in Want and the Format. Please advise. Thanks!
Have | Want | Format |
Jan 9, 2018 | 20180109 | YYMMDDN8 |
April 19,20,25, 2018 | 20180425 | YYMMDDN8 |
June 7 & 11, 2018 | 20180611 | YYMMDDN8 |
July 4 - 16, 2018 | 20180716 | YYMMDDN8 |
Feb 26 - Mar 7, 2018 | 20180307 | YYMMDDN8 |
Like this:
data have;
input Have $ 20. Want yymmdd10. Format $ 10.;
format Want yymmddn8.;
cards;
Jan 9, 2018 20180109 YYMMDDN8
April 19,20,25, 2018 20180425 YYMMDDN8
June 7 & 11, 2018 20180611 YYMMDDN8
July 4 - 16, 2018 20180716 YYMMDDN8
Feb 26 - Mar 7, 2018 20180307 YYMMDDN8
;
run;
data want;
set have;
length m $ 3;
m = scan(compress(Have,,'KAS'), -1);
y = scan(Have, -1);
d = scan(Have, -2);
want_new = input(cats(d,m,y), date9.);
format want_new yymmddn8.;
compare = (want_new = want);
run;
proc print;
run;
?
Like this:
data have;
input Have $ 20. Want yymmdd10. Format $ 10.;
format Want yymmddn8.;
cards;
Jan 9, 2018 20180109 YYMMDDN8
April 19,20,25, 2018 20180425 YYMMDDN8
June 7 & 11, 2018 20180611 YYMMDDN8
July 4 - 16, 2018 20180716 YYMMDDN8
Feb 26 - Mar 7, 2018 20180307 YYMMDDN8
;
run;
data want;
set have;
length m $ 3;
m = scan(compress(Have,,'KAS'), -1);
y = scan(Have, -1);
d = scan(Have, -2);
want_new = input(cats(d,m,y), date9.);
format want_new yymmddn8.;
compare = (want_new = want);
run;
proc print;
run;
?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.