DATA Step, Macro, Functions and more

Libname statement not finding folder with macro variable

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Libname statement not finding folder with macro variable

I am trying to dynamically create a SAS library. A new folder is created every day, title is date and time I.e yyyymmddhhmmss.
An example title would be 20160114134615 (no letters in the folder name)
I pipe in the directory structure, get the folder name I need, and allocate to a macro variable called CheckFolder using an sql select into: statement.
I then try
Libname Sample "&samplePath\&CheckFolder";
I receive NOTE: Library SAMPLE does not exist.
If I were to use :
Libname Sample "&samplePath\20160114134615";
It creates the library no problem.

I have checked the &samplepath variable, there are no issues there.

Is there some general reason this statement fails?

PS: sorry for not posting code, no internet access on my computer so I had to post this from my phone.

Accepted Solutions
Solution
‎08-31-2017 08:43 AM
Super User
Posts: 19,878

Re: Libname statement not finding folder with macro variable

Run the libname statement with the MPRINT and SYMBOLGEN options turned on. It will show what the log is trying to submit and where the error is.

 

It's possible you need a period (.) after the macro variable to force it to resolve properly.

 

Libname Sample "&samplePath.\&CheckFolder.";

View solution in original post


All Replies
Solution
‎08-31-2017 08:43 AM
Super User
Posts: 19,878

Re: Libname statement not finding folder with macro variable

Run the libname statement with the MPRINT and SYMBOLGEN options turned on. It will show what the log is trying to submit and where the error is.

 

It's possible you need a period (.) after the macro variable to force it to resolve properly.

 

Libname Sample "&samplePath.\&CheckFolder.";
Super User
Posts: 5,518

Re: Libname statement not finding folder with macro variable

Your tests clearly narrow the problem down to the value of &CheckFolder.

 

One of the red flags is that &CheckFolder gets created by SQL into.  It's possible that SQL performs a numeric to character conversion when assigning the value.  That might introduce leading blanks, or possibly conversion to scientific notation.  Check what you are getting:

 

%put **&CheckFolder**;

Super User
Super User
Posts: 7,083

Re: Libname statement not finding folder with macro variable

SAS character variables are fixed length fields, so make sure to use the TRIMMED option on the INTO clause.

select charvar_or_function
  into :CheckFolder trimmed
  from ....

Or add a step to remove the trailing spaces.

%let CheckFolder=&CheckFolder;
New Contributor
Posts: 2

Re: Libname statement not finding folder with macro variable

Symbolgen caught the issue, when I formatted the piped in data I was just dropping a single digit from the CheckFolder variable. Thank you all for the help!
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 111 views
  • 3 likes
  • 4 in conversation