BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
tgleghorn
Calcite | Level 5

I am trying to remove trailing spaces from a date so it can be used in a file name for an excel file.  I have tried using strip, left(trim and it is not working 

 

data _null_;
today=today();
format today yymmdd8.;
filedate1=(trim(compress(put(today,yymmdd10.),'-, '))-2);
filedate=strip(filedate1);
format filedate $8.;
call symput ('today',today);
call symput ('filedate',filedate);

run;
%put &today. &filedate.;

libname rh_list "&path.\Export_All_Records &filedate..xlsx";

 

This is the result:

Export_All_Records 20241111  .xlsx

1 ACCEPTED SOLUTION

Accepted Solutions
quickbluefish
Barite | Level 11
Try using call symputX instead of symput.

View solution in original post

9 REPLIES 9
quickbluefish
Barite | Level 11
Try using call symputX instead of symput.
tgleghorn
Calcite | Level 5
I will give this a try. I did figure out what I was doing wrong. moved the format filedate $8 before my strip statement
tgleghorn
Calcite | Level 5
tried the symputx and it worked. using this.. less steps. Thank you so much.
ballardw
Super User

Better yet, use the right format to begin with. The YYMMDDXw. format allows you to specify the separator with common choices based on a different letter in the place of the X. With N meaning NO separator.

So

data _null_;
call symputx('filedate',put(today(),yymmddn8.));
run;

 

 

tgleghorn
Calcite | Level 5
Thank you... will use this 🙂
Tom
Super User Tom
Super User

If you do have a macro variable with leading and/or trailing spaces then the simplest way to remove them is to just run another %LET statement.

%let filedate=&filedate;

 

But you should never use the ancient CALL SYMPUT() method unless you actually need to generate macro variables with leading and/or trailing spaces.

Its replacement, CALL SYMPUTX(), was released by SAS over 30 years ago in version 6 of SAS.

 

tgleghorn
Calcite | Level 5
sorry!!!
FreelanceReinh
Jade | Level 19

@Tom wrote:

But you should never use the ancient CALL SYMPUT() method unless you actually need to generate macro variables with leading and/or trailing spaces.

Its replacement, CALL SYMPUTX(), was released by SAS over 30 years ago in version 6 of SAS.

 


Hi @Tom: I agree that CALL SYMPUTX has been around for decades, but as I remember it as a "newer" feature it can't be that old. Indeed, it is listed in "What's New in the Base SAS 9.0, 9.1, and 9.1.3 Language" and I don't see it in the list "Functions and CALL Routines" of the SAS v8 documentation. It might have been available earlier as an experimental feature, though.

Tom
Super User Tom
Super User

Thanks. So CALL SYMPUTX() is only 20+ years old.  I suspect I got confused with another supplanted feature that still gets used in a lot of new code.  The MISSOVER option of the INFILE statement.  The TRUNCOVER option has been around since at least some release of version 6.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1617 views
  • 0 likes
  • 5 in conversation