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
The query name is
SASUSER.Check
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;
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 No | NAME | Count |
ABCDEFG | AHMED AURANGZAB | 3 |
ABCDEXY | KEVIN | 2 |
XYZYESSA | SHAUN | 2 |
MNBZXDSA | JEREMY | 2 |
PKOIUHTRA | ROGER | 2 |
LKUHJIYGTR | FLEX | 2 |
LAKSIEAUTE | LOREN | 2 |
POUTYAETW | CARLA | 2 |
KKAUEEJYAA | ROBERT | 2 |
LAPEINSNXUE | ALEX | 2 |
The code is giving the above results and now I want to add the query name in the new column, please guide.
thanks
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.