Hi All,
I have deleted my earlier message content as I feel that it's not very clear and also received a response that it's not clear. Can anyone share sample code for date imputations where the input to a macro is a list of char type date variables?
Thanks
I've seen your initial post which was an example of "over-macrotized".
You need to start with a single static example just using a SAS data step and make this work for all the different date patterns you're dealing with.
Only then try to make your code dynamic.
From how I understand your problem there shouldn't be a need for much macro logic at all.
You could start with a simple data step as below until you get it right for all the possible date strings you're dealing with.
data test;
infile datalines truncover;
input date_string $20.;
format dt date9.;
/* try-catch with multiple informats */
dt=input(date_string,?? date9.);
if missing(dt) then dt=input(date_string,?? yymmdd10.);
if missing(dt) then dt=input(date_string,?? ddmmyy10.);
/* more formats as required to cover all the possible date strings */
datalines;
10Jan2023
10-Feb
20231015
15102023
15-10-2023
;
proc print data=test;
run;
Your're right, it's a bit hard to follow you... 🙂
But if you could provide with a relevant input data it might becomes more clear. That in a for of a data step with DATALINES.
Thank you for the reply. Since, I feel that it's not very clear, I will delete this post.
I've seen your initial post which was an example of "over-macrotized".
You need to start with a single static example just using a SAS data step and make this work for all the different date patterns you're dealing with.
Only then try to make your code dynamic.
From how I understand your problem there shouldn't be a need for much macro logic at all.
You could start with a simple data step as below until you get it right for all the possible date strings you're dealing with.
data test;
infile datalines truncover;
input date_string $20.;
format dt date9.;
/* try-catch with multiple informats */
dt=input(date_string,?? date9.);
if missing(dt) then dt=input(date_string,?? yymmdd10.);
if missing(dt) then dt=input(date_string,?? ddmmyy10.);
/* more formats as required to cover all the possible date strings */
datalines;
10Jan2023
10-Feb
20231015
15102023
15-10-2023
;
proc print data=test;
run;
Thank you very much for the example. Yes, I will explore it further.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.