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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.