I would like to assign a library with a macro variable when the pathname includes a numerical folder name.
I want to create a library with the following path;
libname wsale '/sasserver/my_unit/data/Wholesale/201810';
I would like to derive 201810 from the user input which is
%let USER_MTH_END = '31OCT2018'd;
How can I create 201810 and then pass it to the libname statement? I've tried many things but I can't get it to work without manually typing 201810 in the libname statement.
Thanks in advance
data _null_;
call symputx('period',put(&user_mth_end.,yymmn6.));
run;
libname wsale "/sasserver/my_unit/data/Wholesale/&period.";
data _null_;
call symputx('period',put(&user_mth_end.,yymmn6.));
run;
libname wsale "/sasserver/my_unit/data/Wholesale/&period.";
Without double quotes macro variables will not get resolved, they just remain as the string '&...'. The dot following the macro variable isn't technically needed in a lot of scenarios, it it there to tell the macro pre-processor that the macro variable name ends at the point, however in some circumtances it is really required, hence good practice is to always put the point at the end of the macro variable name - it will also highlight it as a macro variable in your code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.