Help using Base SAS procedures

Prompt value in a table name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Prompt value in a table name

Does anyone know how to use a prompted value to select an existing table in a SAS program using EG.  In the example below I am trying to create a table from the values in the table fact_qtr1_year2015.  Can a prompted value be used in a table name.

Example:

Proc SQL;

     Create table work.example as

     select    company,

               portfolio,

               balance

     From libname.Fact_qtr(prompted value)_year(prompted value)

Quit;

run;

   





Accepted Solutions
Solution
‎05-27-2015 03:20 AM
Super User
Posts: 7,111

Re: Prompt value in a table name

The results from user defined prompts in Enterprise Guide are stored in macro variables. So your final "from" would look like this:

From libname.Fact_qtr&qtr._year&year

Note the dot after the first reference to a macro variable; this is necessary so that the macro processor knows it must look for &qtr and not for &qtr_year.

The actual macro variable names depend on the definition of your prompts.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super Contributor
Posts: 275

Re: Prompt value in a table name

You could try to define prompted value as macro variable, such as:

%let qtr=1;

%let year=2015;

Proc SQL;

     Create table work.example as

     select    company,

               portfolio,

               balance

     From libname.Fact_qtr&qut._year&year;

Quit;

Occasional Contributor
Posts: 5

Re: Prompt value in a table name

Thank you for the help.  Worked great

Solution
‎05-27-2015 03:20 AM
Super User
Posts: 7,111

Re: Prompt value in a table name

The results from user defined prompts in Enterprise Guide are stored in macro variables. So your final "from" would look like this:

From libname.Fact_qtr&qtr._year&year

Note the dot after the first reference to a macro variable; this is necessary so that the macro processor knows it must look for &qtr and not for &qtr_year.

The actual macro variable names depend on the definition of your prompts.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 777 views
  • 2 likes
  • 3 in conversation