I have done this 2 ways: a. use %let = variablename (such as year, month day) and then referencing them as macro variables or b. use a data step to set the variables and then referencing them as macro variables Using method a: %let rundate = %SYSFUNC(today(),yymmddn8.); %let runhour = %SYSFUNC(HOUR(%SYSFUNC(time(), MINUTE.)), Z2.); %let runmin = %SYSFUNC(MINUTE(%SYSFUNC(TIME(), MINUTE.)), Z2.); then set variable to use the above values: %let exportfile="REPORT_as_of_&rundate._&runhour.&runmin..xml"; Note the extra period after each macro variable when it is referenced using &. OR Using method b: Create a table that gets the "rundate": PROC SQL; CREATE TABLE WORK.GET_REPORT_RUNDATE AS SELECT DISTINCT /* REPORT_RUNDATE */ (DATETIME()) FORMAT=NLDATM30. AS REPORT_RUNDATE FROM WORK.GET_ALL_TESTS t1; QUIT; Then use a data step to break apart the datetime: data temp; set work.get_report_rundate; rundate = datepart(report_rundate); year = year(rundate); month = month(rundate); runtime = timepart(report_rundate); hour = hour(runtime); minute = minute(runtime); format month z2.; format hour z2.; format minute z2.; charmonth = put(month, z2.); charhour = put(hour, z2.); charmin = put(minute, z2.); reportrundate = year||charmonth||'_'||charhour||charmin; run; Then, reference those macro variables : %let exportfile="REPORT_as_of_&rundate._&runhour.&runmin..xml";
... View more