BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GuiVtzl
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
MichelleHomes
Meteorite | Level 14

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.

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

View solution in original post

7 REPLIES 7
MichelleHomes
Meteorite | Level 14

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

  • Open the program item in which you want to use a prompt and click Properties on the workspace toolbar. The Properties for program-name window opens. (Note: You can also right-click the program item in the project tree or process flow and select Properties.)
  • Click Prompts in the selection pane, and then click Add. The Select Prompts dialog box opens.
  • Select the prompt that you want to associate with the program item and click OK.
  • Click OK to close the Properties dialog box.
  • Edit the program file in which you want to use a prompt. The prompt should be added to the code as &prompt-name.

You seem to have done the last bullet point above...

Hope this helps.

Kind Regards,

Michelle

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
GuiVtzl
Fluorite | Level 6

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.

bsanders
Calcite | Level 5

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

MichelleHomes
Meteorite | Level 14

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.

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
GuiVtzl
Fluorite | Level 6

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 ?

MichelleHomes
Meteorite | Level 14

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.

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
GuiVtzl
Fluorite | Level 6

Thanks a lot for your help and enlightment !

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2947 views
  • 8 likes
  • 3 in conversation