3

It appears that when performing an explicit pass-through with SAS, the text is not delivered to the server in the same manner that it is laid out within the editor or .sas file itself. SAS appears to be delivering the text all on a single line.

This presents a problem when you're passing a query with --comments.

Example:

The following code will be "flattened" within a PROC SQL explicit pass-through:

SELECT * --this is my comment
FROM myTable
WHERE
    1 = 1

and the server will receive it like this:

SELECT * --this is my comment FROM myTable WHERE 1 = 1

As you can see, everything after the comment's dashes is....commented.

Is anyone aware of a special option or configuration that can be used with PROC SQL to ensure this doesn't happen? I am aware that with SAS, each of those comments could be converted to:

/*comments like this*/

But for the sake of this question, let's pretend that's not an option and that it is necessary to maintain the --comments in the code.

EDIT: I should note that I am performing this explicit pass-through to an IBM Netezza database.

Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
  • 1
    Which particular DBMS are you connecting to? – user667489 Jan 30 '18 at 14:34
  • @user667489 - IBM Netezza. Maybe I should have added that? – Joshua Schlichting Jan 30 '18 at 15:09
  • 1
    Ahhh, I always wondered why `-- ` style comments broke my passthrough... – Robert Penridge Jan 30 '18 at 15:15
  • 1
    @user667489 I have this same issue on mySQL – Robert Penridge Jan 30 '18 at 15:15
  • @RobertPenridge there HAS to be a way to work around this, some sort of option to turn on before or alongside the PROC SQL! – Joshua Schlichting Jan 30 '18 at 15:17
  • 1
    @JoshuaSchlichting I like your optismism. – Robert Penridge Jan 30 '18 at 15:18
  • @JoshuaSchlichting It's entirely possible that this is an ODBC driver issue. I just tested a query with that style of comment from within excel against an ODBC connection and it broke there as well. The other comment syntax worked fine. I tried testing various ODBC connection settings and couldn't find anything that would allow it to work – Robert Penridge Jan 30 '18 at 15:26
  • I'm not even sure that you can fix this with a macro - as SAS removes linefeed/returns from macro variables. How are you getting this code into SAS? Is it in a text file that you're `%include`ing or something? – Joe Jan 30 '18 at 15:54
  • @Joe This is the text that is within the PROC SQL pass-through. PROC SQL; CONNECT TO serveralias(connection string here); CREATE TABLE exampletable AS SELECT * FROM connection to serveralias ( the query in question here) ; QUIT; – Joshua Schlichting Jan 30 '18 at 16:00
  • @JoshuaSchlichting Right, but I'm asking how does it get there. You phrase the question as if you cannot easily not have the `--` comments in there, so I assume this is code that's coming from somewhere else, either auto-generated or something similar? – Joe Jan 30 '18 at 16:01
  • @Joe I realize the comments may not be the best place for the code example. I omitted it from the post/question because I felt this had more to do with the nested text being altered, and not so much with the PROC SQL itself. If you think it would be a necessary addition to help gain more understanding of the context, I can go ahead and add that in there. – Joshua Schlichting Jan 30 '18 at 16:02
  • 1
    @Joe Oh I see what you mean. Really, the need to have the --format is because I'm not really developing these queries within SAS. I develop them in Aginity Workbench, and when they're good to go, I port them over into SAS (aka copy paste). Aginity Workbench allows me to organize large queries with --region MyRegion --endregion tags. So, I don't want to lose those region tags on my large queries that I paste into there, because I want to be able to easily port (copy-paste) these queries from SAS back into Aginity Workbench for later development. – Joshua Schlichting Jan 30 '18 at 16:05

4 Answers4

2

I don't believe this is a SAS issue at all but a ODBC driver issue.

I am able to replicate the issue against ODBC connections to a mySQL database, and also replicate the issue using the same ODBC connections from programs other than SAS.

Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
  • You may be right, Robert. I'm waiting to hear back from SAS themselves before I accept an answer here. I'm still uncertain on what side of the fence this issue falls on - SAS or the database. I have noticed that there is a PRESERVE_COMMENTS option for Oracle DB pass-throughs. Looking into this more right now. Thanks for contributing! – Joshua Schlichting Jan 30 '18 at 17:25
  • 2
    PRESERVE_COMMENTS for Oracle is for preserving hints that you can embed inside of /* */ comments. Instead of removing those (since they are just comments) SAS sends them on to Oracle so the hidden hints inside of them can be processed by Oracle. – Tom Jan 30 '18 at 17:42
1

There appears to be no documented option within proc SQL that does this. You could try asking SAS technical support to see if they have any suggestions.

My own suggestion would be to apply a regex substitution to the query string to remove any comments prior to submitting it via pass- through.

user667489
  • 9,501
  • 2
  • 24
  • 35
  • I've got an email out to SAS Technical Support via the SAS admins at the office. I'll see about accepting an answer based on what we hear back from them. Thanks for your contribution to the discussion! – Joshua Schlichting Jan 30 '18 at 17:23
1

Alright, I really hate to answer my own question on SO, but this is the official answer from SAS Technical Support (support@sas.com):

Hello Joshua, I did some additional checking on this. Unfortunately SAS does not preserve the line breaks as you have noticed. Additionally the SAS/ACCESS engine does not have a function such as PRESERVE_COMMENTS seen in the Oracle engine. There is no real way to force this to be passed with the line breaks. The block comments will be the next best option. I am sorry for the inconvenience. Please let me know if there are any questions or concerns.

Thank you,

Sean

Community
  • 1
  • 1
Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
0

How the string is highlighted when pasted into StackOverFlow shouldn't matter. It is what the database does when it receives that string. Does it consider the double hyphen as an attempt to subtract some value that has had the negation operator prefixed to it? Or does it treat it like an end of line comment?

At least with Teradata the database is recognizing the -- as starting a comment, but since it is only getting one line of code it comments out all of the rest of the code.

 70         select * from connection to td
 71         (select 1+2 -- Comment in line
 72           +3 as name
 73           , 4+5 as value
 74         
 75         )
 76         ;

 TERADATA_0: Prepared: on connection 0
 select 1+2 -- Comment in line +3 as name , 4+5 as value

So it runs without error, but it just returns a single value of 3 since that is the sum of 1 and 2.

Also note that in SAS -- has no special meaning. It is just two - next to each other. Try this query and you will see that X has the same value as AGE.

select name,age,--age as x
from sashelp.class
;

Either use your source code with the end of line comments to create a stored process in your database that you can call from SAS or remove the end of line comments before including them in your PROC SQL code.

Tom
  • 47,574
  • 2
  • 16
  • 29
  • Same exact issue. This is not really an answer I can accept, but I truly appreciate the contribution to the discussion! I'm waiting to hear back from SAS Technical Support before accepting an answer on this one. – Joshua Schlichting Jan 30 '18 at 17:22
  • I see your edits here and I think there may be something lost in translation. I feel like I've addressed your questions already with the information provided in the question. The query is being reduced to a single line of code. So any code after a -- is considered to be a comment. This is within an explicit pass-through, so there isn't any attempt to get SAS itself to use double dashes. I just want to pass code through an explicit pass-through while maintaining the multi-line format of the query. This way, only code on the same line (and to the right) as the -- is considered to be a comment. – Joshua Schlichting Jan 31 '18 at 02:26