BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dougall
Fluorite | Level 6
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.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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.";
Astounding
PROC Star

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**;

Tom
Super User Tom
Super User

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;
Dougall
Fluorite | Level 6
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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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