BookmarkSubscribeRSS Feed
melhaf
Fluorite | Level 6

if I resolve my macro variables like this

%let YEAR=2023:
%let FRUIT=orange;   
%let TOPPING= chocolate;
%let Path= "C:\Deskop\My folder\";

libname results_1 "&Path.\Data\&FRUIT.\&TOPPING\&Year.";  /*this works*/
libname results_2 "&Path.&Year.\Data\&FRUIT.\&TOPPING.";  /*this don't work, and I would like this one to work since it is more efficient */

The error i get is: 

107 libname results_1;
NOTE: Libref OUT was successfully assigned as follows:
Engine: V9
Physical Name: ....

108 libname results_2
ERROR: Create of library results_2 failed.
ERROR: Error in the LIBNAME statement.

How do I solve this?
4 REPLIES 4
yabwon
Onyx | Level 15

If directory: 

"&Path.&Year.\Data\&FRUIT.\&TOPPING."

does not exist, you won't be able to assign a library.

 

Remember libname statement does NOT create directories, it assigns libref to existing one.

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



FreelanceReinh
Jade | Level 19

Hello @melhaf,

 

  1. Librefs cannot be longer than 8 characters (see documentation of the LIBNAME statement), so results_n is too long.
  2. Omit the quotation marks in the %LET statement for macro variable Path. Otherwise they will be duplicated in your LIBNAME statements. Ideally, avoid the unwanted duplication of backslashes, too.
  3. Even with the DLCREATEDIR system option you can only create one folder at a time, so use a step-by-step approach or use other methods to create the folders beforehand:
    libname res2 "&Path.\&Year.";
    libname res2 "&Path.\&Year.\&FRUIT.";
    libname res2 "&Path.\&Year.\&FRUIT.\&TOPPING.";
ballardw
Super User

@melhaf wrote:

if I resolve my macro variables like this

%let YEAR=2023:
%let FRUIT=orange;   
%let TOPPING= chocolate;
%let Path= "C:\Deskop\My folder\";

libname results_1 "&Path.\Data\&FRUIT.\&TOPPING\&Year.";  /*this works*/
libname results_2 "&Path.&Year.\Data\&FRUIT.\&TOPPING.";  /*this don't work, and I would like this one to work since it is more efficient */

The error i get is: 

107 libname results_1;
NOTE: Libref OUT was successfully assigned as follows:
Engine: V9
Physical Name: ....

108 libname results_2
ERROR: Create of library results_2 failed.
ERROR: Error in the LIBNAME statement.

How do I solve this?

I want to see  your LOG where the "this works" actually assigned a library. I expect unbalanced quotes to generate an error

%let Path= "C:\Deskop\My folder\"; libname results_1 "&Path.\Data\&FRUIT.\&TOPPING\&Year.";

Would create this line of code:
libname results_1 ""C:\desktop\My Folder\"\Data\orange\chocolate\2023";

The quotes around the PATH portion of your string would almost certainly cause an error in BOTH libname statements.

 

 

Sajid01
Meteorite | Level 14

Hello @melhaf 
I agree with what @ballardw has said.
You must modify your path statement as follows

%let Path= C:\Desktop\My folder ;

As a reminder while creating a macro variable, anything between the = and semicolon  ; are a part of the macro variable including quotes.

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
  • 404 views
  • 2 likes
  • 5 in conversation