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
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;
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.
@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.
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.