- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-26-2024 04:33 AM
(1079 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello @melhaf,
- Librefs cannot be longer than 8 characters (see documentation of the LIBNAME statement), so results_n is too long.
- 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.
- 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.";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content