I have a macro variable containing the file name. The file name is in this format: ABC_DE___January_7__2019_2019_12_20 I need to extract the date January 7, 2019 from this macro variable and assign it to another macro variable using call symput. This is my code so far: %let filename = ABC_DE___January_7__2019_2019_12_20;
data _null_;
set a;
call symput('file_year', trim(left(%scan(&filename., 5, _))));
call symput('file_month', trim(left(%scan(&filename., 3, _))));
call symput('file_day', trim(left(%scan(&filename., 4, _))));
run; If I call on the %put statement, I get the following results: file_year = 2019 file_day = 7 file_month = (blank) In the log, it says "Variable January is uninitialized" I don't understand how the file_month could be blank considering that they are all delimited by underscores. There are 3 underscores before the month; 1 underscore before the day, and 2 underscores before the year. If it's because of multiple underscores, then why was SAS able to successfully extract the file_year? Is it because the month is in text form, not number form? I would need to convert the month from text to number as well. I tried adding in a input(file_month, month.) but to no avail.
... View more