Solved

SAS Variable resolution on DB2 pass-thru PROC SQL

Posted on 2014-01-08
4
651 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

Independent Software Vendors: 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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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