Hello,
This should be fairly simple, but can't find a solution. When I export to an Excel file, I want the file name to appear as "ABA_RATE_REVIEW (7.10.2014).xls", but for some odd
reason the file name appears as "ABA_RATE_REVIEW (7.10.2014 ).xls", that extra space (trailing blank in the date) keeps appearing before the ending parenthesis. I've tried COMPRESS, TRIM, but none those seem to work in the code.
Here is the current code:
Data _null_;
datefmt = DATE()
TITLEDT = Put (MONTH(datefmt), Z2.) || Put (DAY(datefmt), Z2.) || SUBSTR(LEFT(TRIM(RIGHT(YEAR(datefmt)))),1,4);
Call SYMPUT ('WEEK_DT', TITLEDT);
Run;
Proc Export Data = ABA
DBMS = Excel Replace
Outfile = "C:\Documents\ABA_RATE_REVIEW (&WEEK_DT).xls";
Sheet = ABA;
Run;
Would anybody happen to have a solution ?
Thank you in advance.
You can also skip the data step entirely and use the format mmddyyp10. to get your macro variable.
%let week_dt=%sysfunc(date(), mmddyyp10.);
%put &week_dt;
title "this is the correct title (&week_dt)";
proc means data=sashelp.class;
run;
Try call symputx instead of call symput when creating your macro variable.
Hi,
Use trim in Call symput as follows.
Data _null_;
datefmt = DATE();
TITLEDT = Put (MONTH(datefmt), Z2.) || Put (DAY(datefmt), Z2.) || SUBSTR(LEFT(TRIM(RIGHT(YEAR(datefmt)))),1,4);
Call SYMPUT ('WEEK_DT', trim(TITLEDT));
Run;
%put &WEEK_DT;
And you may want to investigate using on of the CATT CATS CATX functions instead of concatenating multiple variables with || as those functions can strip leading and/or trailing spaces from each component without additional function calls to TRIM, LEFT or STRIP.
You can also skip the data step entirely and use the format mmddyyp10. to get your macro variable.
%let week_dt=%sysfunc(date(), mmddyyp10.);
%put &week_dt;
title "this is the correct title (&week_dt)";
proc means data=sashelp.class;
run;
Thank you ! This worked perfectly.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.