Solved

SAS Variable resolution on DB2 pass-thru PROC SQL

Posted on 2014-01-08
4
605 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now