DATA Step, Macro, Functions and more

How to use a prompt in a LIBNAME statement ?

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

How to use a prompt in a LIBNAME statement ?

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


Accepted Solutions
Solution
‎09-16-2013 03:22 PM
Trusted Advisor
Posts: 1,322

Re: How to use a prompt in a LIBNAME statement ?

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.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,322

Re: How to use a prompt in a LIBNAME statement ?

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

Contributor
Posts: 40

Re: How to use a prompt in a LIBNAME statement ?

Posted in reply to MichelleHomes

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.

New Contributor
Posts: 4

Re: How to use a prompt in a LIBNAME statement ?

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

Trusted Advisor
Posts: 1,322

Re: How to use a prompt in a LIBNAME statement ?

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.

Contributor
Posts: 40

Re: How to use a prompt in a LIBNAME statement ?

Posted in reply to MichelleHomes

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 ?

Solution
‎09-16-2013 03:22 PM
Trusted Advisor
Posts: 1,322

Re: How to use a prompt in a LIBNAME statement ?

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.

Contributor
Posts: 40

Re: How to use a prompt in a LIBNAME statement ?

Posted in reply to MichelleHomes

Thanks a lot for your help and enlightment !

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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