DATA Step, Macro, Functions and more

SAS Macro Dates and Libname

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

SAS Macro Dates and Libname

I need help with the following. Im not a SAS guru. Im in the process of building automated SAS runs, the SAS code need to autoupdate the libname with the current month's date (however the day will ALWAYS be the 7th).

 

the libname should look like this this month:

libname mylib 'C:\Users\folder1\Folder2\2017-06-07'

next month:

libname mylib 'C:\Users\folder1\Folder2\2017-07-07'

the month after that

libname mylib 'C:\Users\folder1\Folder2\2017-08-07'

 

I struggle with this , please assist.


Accepted Solutions
Solution
‎06-07-2017 06:29 AM
Super User
Posts: 6,938

Re: SAS Macro Dates and Libname

Then you should determine the date like that:

data _null_;
mydate = input(put(today(),yymmn6.) !! '07',yymmdd8.);
call symput('d',put(mydate,yymmddd10.));
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Super User
Posts: 7,401

Re: SAS Macro Dates and Libname

This should work:

data _null_;
  call symputx('D',put(intnx('month',today(),0,'b'),yymmdd10.));
run;
libname mylib 'C:\Users\folder1\Folder2\&d.';
Super User
Posts: 6,938

Re: SAS Macro Dates and Libname

Just what @RW9 suggested, but with one little caveat:

libname mylib "C:\Users\folder1\Folder2\&d.";

Note the double quotes, single quotes would prevent the resolution of the macro variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: SAS Macro Dates and Libname

@KurtBremser @RW9 

Thank you for the quick responses, i still struggle with the hardcoding of the 7th day in the same question.

Solution
‎06-07-2017 06:29 AM
Super User
Posts: 6,938

Re: SAS Macro Dates and Libname

Then you should determine the date like that:

data _null_;
mydate = input(put(today(),yymmn6.) !! '07',yymmdd8.);
call symput('d',put(mydate,yymmddd10.));
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: SAS Macro Dates and Libname

@KurtBremser

Much appreciated!

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 101 views
  • 1 like
  • 3 in conversation