Hello everyone,
I've been tyring to use a prompt in a LIBNAME statement, but I can't make it work. Could you help me please ?
Here's my code :
LIBNAME TRAVAIL 'C:\SAS_TEST\&User';
run;
I use a prompt to create a macrovariable "User" which can take names such as Guillaume, John, Mike etc.
Thank you
It is a fundamental of macro processing. The macro reference guide contains detail information, http://support.sas.com/documentation/cdl/en/mcrolref/64754/HTML/default/viewer.htm#n1nks63d6g1rk2n1o...
if the question has been answered to your satisfaction please mark it as answered.
Hi,
From your description it seems that you have created a prompt using SAS Enterprise Guide and have a program where you are using the underlying macro variable from the prompt but it isn't resolving. Is this correct?
It seems that you may have missed the additional step of associating the prompt with your program. The steps (taken from the online SAS Enterprise Guide help) are as follows:
---
To associate an existing prompt with a program
You seem to have done the last bullet point above...
Hope this helps.
Kind Regards,
Michelle
Hello Michelle, thanks for your help
Indeed I'm using EG. In fact, I added the prompt to the program, I think that is a syntax problem I am facing here.
When I used the code above, I've got this error in the log :
"
/* Importation de la K_REPORTING. Constitution des INPUTS #1 */
24 LIBNAME TRAVAIL 'C:\SAS_TEST\&User.'; "
In fact it does not even resolve the prompt with the value I entered (which is Guillaume)
Then I tried this code (The error seems to be with the quotation marks, I don't know what syntax to use to correctly write the path to the library with my prompt):
LIBNAME TRAVAIL 'C:\SAS_TEST\'&User.;
run;
/* Importation de la K_REPORTING. Constitution des INPUTS #1 */
24 LIBNAME TRAVAIL 'C:\SAS_TEST\'&User.;
NOTE: Line generated by the macro variable "USER".
24 'C:\SAS_TEST\'Guillaume
_______________________
49 22
ERROR: Nom TRAVAIL non attribué.
ERROR: Error in the LIBNAME statement.
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.
Inserting white space between a quoted string and the succeeding identifier is
recommended.
ERROR 22-7: Nom d'option GUILLAUME incorrect.
G.
Have you tried double quotes around the libname path?
LIBNAME TRAVAIL "C:\SAS_TEST\&User";
I haven't tried it in EG, but if I use the original code in base SAS, I'm told the library doesn't exist. If I use the double quotes, it resolves and creates the library.
Good luck,
Blake
You need to have double quotes around the path. The macro compiler will not resolve a macro variable within single quotes as it is treated as a literal. The text is then passed to the SAS compiler and it fails as it is incorrect SAS code.
LIBNAME TRAVAIL "C:\SAS_TEST\&User";
will resolve correctly and the SAS code will be valid as long as the macro variable value is correct and the folder exists.
Oh yes ! It works !
Thank you both !
Just for a better understanding, could you please explain to me quickly the difference between single and double quotes ?
It is a fundamental of macro processing. The macro reference guide contains detail information, http://support.sas.com/documentation/cdl/en/mcrolref/64754/HTML/default/viewer.htm#n1nks63d6g1rk2n1o...
if the question has been answered to your satisfaction please mark it as answered.
Thanks a lot for your help and enlightment !
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.