DATA Step, Macro, Functions and more

Creating library path at the time of the Base SAS runs in Windows Scheduler

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Creating library path at the time of the Base SAS runs in Windows Scheduler

We have a SAS code that is run in Base SAS that is run quarterly. It creates data sets in different folders on a server depending on month and the year.  Bleow is the code I was using with replacing x's where our server name and network inofrmation.  Also I included the log with the error.  Can anyone help or suggest another way of do this.  We are trying not to modify the program every time the job is schedule to run.


%macro LibPath ();
%let m = %substr(&sysdate9,3,3);
%let y = %substr(&sysdate9,6,4);
%put &m;
%put &y;

%if &m=JAN %then %do;
%let Q=E:\Loans Data\Fourth Quarter ;
%end;
%if &m=APR %then %do;
%let Q=E:\Loans Data\First Quarter ;
%end;
%if &m=JUL %then %do;
%let Q=E:\Loans Data\Second Quarter ;
%end;
%if &m=OCT %then %do;
%let Q=E:\Loans Data\Third Quarter ;
%end;

%put &Q;

%if &m=JAN %then %do;
%let y=%eval(&y - 1);
%end;
%else %do;
%let y= &y;
%end;
%put &y;


%let LibraryPath = %quote(%str(&Q &y));
%put &LibraryPath;


%let mynode=xxxxxxxx 3232;
options comamid=tcp remote=mynode;
signon;


libname PROP_DB &LibraryPath server=Mynode;

%mend;

%LibPath();

1
2    %macro LibPath ();
3    %let m = %substr(&sysdate9,3,3);
4    %let y = %substr(&sysdate9,6,4);
5    %put &m;
6    %put &y;
7
8    %if &m=JAN %then %do;
9        %let Q=E:\Loans Data\Fourth Quarter ;
10   %end;
11   %if &m=APR %then %do;
12       %let Q=E:\Loans Data\First Quarter ;
13   %end;
14   %if &m=JUL %then %do;
15       %let Q=E:\Loans Data\Second Quarter ;
16   %end;
17   %if &m=OCT %then %do;
18       %let Q=E:\Loans Data\Third Quarter ;
19   %end;
20
21   %put &Q;
22
23   %if &m=JAN %then %do;
24       %let y=%eval(&y - 1);
25   %end;
26   %else %do;
27   %let y= &y;
28   %end;
29   %put &y;
30
31
32   %let LibraryPath = %quote(%str(&Q &y));
33   %put &LibraryPath;
34
35
36   %let mynode=xxxxxxxx 3232;
37   options comamid=tcp remote=mynode;
38   signon;
39
40
41
42
43   libname PROP_DB &LibraryPath server=Mynode;
44
45 
50
51   %mend;
52
53   %LibPath();
JAN
2012
E:\Loans Data\Fourth Quarter
2011
E:\Loans Data\Fourth Quarter 2011
NOTE: Remote signon to MYNODE commencing (SAS Release 9.01.01M3P020206).
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
NOTE: Copyright (c) 2002-2008 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.2 (TS2M3)
      Licensed to NY HIGHER EDUCATION SERVICES CORP, Site 70061030.
NOTE: This session is executing on the X64_ESRV08  platform.

NOTE: SAS initialization used:
      real time           0.34 seconds
      cpu time            0.39 seconds

NOTE: Remote signon to MYNODE complete.
ERROR: The E engine cannot be found.
ERROR: Error in the LIBNAME statement.
ERROR: Libname PROP_DB is not assigned.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

Thanks for your help.  I hope that I chose the right area.

Bridget Nelson


Accepted Solutions
Solution
‎01-04-2012 01:30 PM
Super User
Super User
Posts: 7,039

Creating library path at the time of the Base SAS runs in Windows Scheduler

Posted in reply to Bridget53

Did you try just adding quotes around the path that you have calculated?

libname PROP_DB %sysfunc(quote(&LibraryPath)) server=Mynode;

View solution in original post


All Replies
Solution
‎01-04-2012 01:30 PM
Super User
Super User
Posts: 7,039

Creating library path at the time of the Base SAS runs in Windows Scheduler

Posted in reply to Bridget53

Did you try just adding quotes around the path that you have calculated?

libname PROP_DB %sysfunc(quote(&LibraryPath)) server=Mynode;

Occasional Contributor
Posts: 7

Creating library path at the time of the Base SAS runs in Windows Scheduler

Posted in reply to Bridget53

Thanks Tom it work. We spent most of the morning trying to work on it and just could not figure out how to get the quotes there.  Thanks again.

Trusted Advisor
Posts: 1,301

Creating library path at the time of the Base SAS runs in Windows Scheduler

Posted in reply to Bridget53

You could also literally add the quotes:

libname PROP_DB "&LibraryPath" server=Mynode;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 3 in conversation