Solved

SAS Variable resolution on DB2 pass-thru PROC SQL

Posted on 2014-01-08
4
642 Views
Last Modified: 2016-02-10
So I am running into a problem when I run the code below.  I tested the pass-thru portion first with constants to validate if it worked.  I then included it in my do loop with variables.
In the feedback log, the first 2 variables "&TABLENAME" and "&VARNAME&II." are resolving correctly, but the double quotes remain.  This causes the pass thru to try to us the variables as valid fields to select, when I only want the value to be part of the result set.

I have tried single quotes, single quotes inside double quotes, and double quotes inside single quotes.  None of these work.  Any suggestions?

%do II=1 %to &NUMVARS.;

      PROC SQL THREADS FEEDBACK;
            CONNECT TO ODBC (DSN=XXXX USER=XXXXX PASSWORD=XXXXX);
                  create table work.query_output as
                        select "&TABLENAME." as table_name
                              ,"&VARNAME&II." as field_name
                              ,4 as test_num
                              ,ROW_NUMBER() OVER () as seq_nbr
                              ,&&VARNAME&II. as value
                              , count(1) as results
                        from PRDOTCDTA.&TABLENAME.
                        group by &&VARNAME&II.
                        order by results desc
                        fetch first 10 rows only);
      quit;
      %output_creation;

    %if &II. ne &NUMVARS. %then %do;
         %end;
%end;
0
Comment
Question by:rkellow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 250 total points
ID: 39769220
Not an SAS guy, so this may not be helpful, but looking at this documentation, I don't understand why you are including any quotes at all.  

In this example, it looks like they aren't required:

http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#uptqs.htm

- Gary Patterson
0
 
LVL 16

Assisted Solution

by:theo kouwenhoven
theo kouwenhoven earned 250 total points
ID: 39769380
If you must include the quotes, then remove them from your sql command an add them to the contents of varibles &TABLENAME, &VARNAME and &II.
Eventually make a new var that concat &VARNAME and &II (quoted)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question