Desktop productivity for business analysts and programmers

Retrieving query name in results

Reply
Occasional Contributor
Posts: 16

Retrieving query name in results

Hi - I wrote following code to export results in excel, but I also want to retrieve query name along with the result. The code is as follows:

proc export data = SASUSER.Check

outfile = "C:\Documents\test\Alerts.xls"

dbms = excel replace;

sheet = "Check";

run;

The above code generates the excel file and replace it every time when I run the code and it works fine but for reference I need to add query name. Please help

thanks

Esteemed Advisor
Posts: 6,646

Re: Retrieving query name in results

What is the "query name"?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 16

Re: Retrieving query name in results

The query name is

SASUSER.Check

Esteemed Advisor
Posts: 6,646

Re: Retrieving query name in results

Then you could use a macro variable to name the sheet like that:

%let query_name=sasuser.check;

proc export data = &query_name

outfile = "C:\Documents\test\Alerts.xls"

dbms = excel replace;

sheet = "&query_name";

run;

or

%let libraryname=sasuser;

%let query_name=check;

proc export data = &libraryname..&query_name

outfile = "C:\Documents\test\Alerts.xls"

dbms = excel replace;

sheet = "&query_name";

run;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 16

Re: Retrieving query name in results

The above code is running perfectly now I have summarized all the queries in one excel sheet using the following code:

PROC SORT DATA=SASUSER.QUERY_FOR_APPEND_TABLE_0000;

BY DESCENDING 'Alert Count'n;

RUN;

Ref NoNAMECount
ABCDEFGAHMED AURANGZAB3
ABCDEXYKEVIN2
XYZYESSASHAUN2
MNBZXDSAJEREMY2
PKOIUHTRAROGER2
LKUHJIYGTRFLEX2
LAKSIEAUTELOREN2
POUTYAETWCARLA2
KKAUEEJYAAROBERT2
LAPEINSNXUEALEX2

The code is giving the above results and now I want to add the query name in the new column, please guide.

thanks

Ask a Question
Discussion stats
  • 4 replies
  • 270 views
  • 0 likes
  • 2 in conversation