BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
suncawy
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

Try call symputx instead of call symput when creating your macro variable.

Vish33
Lapis Lazuli | Level 10

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;

ballardw
Super User

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.

Reeza
Super User

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;

suncawy
Obsidian | Level 7

Thank you !  This worked perfectly.

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1894 views
  • 6 likes
  • 4 in conversation