Solved

SAS Variable resolution on DB2 pass-thru PROC SQL

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL: New to using transactions 9 53
LAG_ROWID - how do I get the right order using this query? 2 22
MS SQL GROUP BY 6 71
Fuzzy search functionality DB2 UDB 3 30
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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