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.
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
Hello @melhaf,
libname res2 "&Path.\&Year."; libname res2 "&Path.\&Year.\&FRUIT."; libname res2 "&Path.\&Year.\&FRUIT.\&TOPPING.";
@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.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.