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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1875 views
  • 6 likes
  • 4 in conversation