Solved

SAS Variable resolution on DB2 pass-thru PROC SQL

Posted on 2014-01-08
4
616 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
4 Comments
 
LVL 34

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help With Database JOIN 7 28
SELECT query on two levels (detail and summary) 13 50
Mysql Left Join Case 10 55
2 IIF's in Access query 25 30
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

778 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