Help using Base SAS procedures

Splitting the compacted SQL into simple two pieces?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Splitting the compacted SQL into simple two pieces?

Hi SAS Forum,

Another worker has written below compacted code.

/*COMPACTED CODE*/

%let age0=1303;

%let yymm=1303 1304 1305 1306 1307  ;

proc sql;

create table OUR_age0 as

select               a.*,

                     b.LOAN_LIMIT,

                     b.DEPOSIT,

                     "&age0" as year_month

from   (select       a.*

                     from   LOCATION.FILE_1    as             a inner join

               ABCD.INCOME_&age0  as             b on

               a.ACT_NO=b.ACCOUNT_NUMBER

                     where b.STATUS^="CLOSED")    as            a inner join

                     ABCD.EXPENSES_&age0      as b on a.ACT_NO=b.ACCOUNT_NUMBER

;

quit;

/*I HAVE SPLIT ABOVE COMPACTED CODE INTO simple 2 PIECES*/

/*PIECE 1 – YELLOW PORTION ABOVE*/

Proc sql;

Create table any_name as

select        a.*

              from   LOCATION.FILE_1      as            a inner join

                     ABCD.INCOME_&age0    as            b on

                     a.ACT_NO=b.ACCOUNT_NUMBER

                     where b.STATUS^="CLOSED";

quit;

run;

/*PIECE 2*/

proc sql;

create table OUR_age0_testing as

select               a.*,

                     b.LOAN_LIMIT,

                     b.DEPOSIT,

                     "&age0" as year_month

from   any_name             as            a inner join

       ABCD.EXPENSES_&age0        as            b on

  1. a.ACT_NO=b.ACCOUNT_NUMBER

;

Quit;

Run;

/*QUESTION*/

Final files produced by the compacted code and split two pieces have to be identical but following shows it is not.

proc compare base=Our_age0_testing compare=Our_age0 ;run;

Could anyone help me to split the compacted code correctly?

Thanks


Accepted Solutions
Solution
‎05-09-2014 04:38 PM
Regular Contributor
Posts: 213

Re: Splitting the compacted SQL into simple two pieces?

OK, my bad!

I misunderstood your original question.

You are asking how to re-write the query for testing purposes, while my answer was primarily related to Parsing the entire query, from a SQL syntax point of view!

Here is what I think the correct re-write should be:

%let age0=1303;

%let yymm=1303 1304 1305 1306 1307  ;

PROC SQL;

    CREATE TABLE Table1 AS /* Original In-Line Query named as Table1 */

    SELECT    a.*

         FROM    LOCATION.FILE_1 as a inner join ABCD.INCOME_&age0 AS b

         ON    a.ACT_NO=b.ACCOUNT_NUMBER

         WHERE b.STATUS^="CLOSED";

        

     CREATE TABLE OUR_age0_testing AS

    SELECT    a.*,

          b.LOAN_LIMIT,

          b.DEPOSIT,

          "&age0" as year_month

    FROM        Table1 /* Using Table1 as a replacement to the original In-Line Query */

     INNER JOIN ABCD.EXPENSES_&age0 AS b

         ON a.ACT_NO=b.ACCOUNT_NUMBER;

QUIT;

Thanks,

Ahmed

View solution in original post


All Replies
Regular Contributor
Posts: 213

Re: Splitting the compacted SQL into simple two pieces?

I would recommend using Regular Expression to extract the "Compacted Code" into separate file.

That could be one solution to your question.

You are asking for help in Parsing standard SQL query syntax.

Alternatively, search the Web for Open Source SQL Query Parser.

Good luck,

Ahmed

Super Contributor
Posts: 338

Re: Splitting the compacted SQL into simple two pieces?

Hi Ahmed,

Thank you for your response.

However, my level is not enough to understand what you suggested. I googled what is "Regular Expression". It looks like an another entire areas which I have not even touched.

Could you or someone help me to understand what is the wrong I have done in splitting the compacted code (which has a sub query) into the two simple pieces?

Thanks for the expertise and time.


Solution
‎05-09-2014 04:38 PM
Regular Contributor
Posts: 213

Re: Splitting the compacted SQL into simple two pieces?

OK, my bad!

I misunderstood your original question.

You are asking how to re-write the query for testing purposes, while my answer was primarily related to Parsing the entire query, from a SQL syntax point of view!

Here is what I think the correct re-write should be:

%let age0=1303;

%let yymm=1303 1304 1305 1306 1307  ;

PROC SQL;

    CREATE TABLE Table1 AS /* Original In-Line Query named as Table1 */

    SELECT    a.*

         FROM    LOCATION.FILE_1 as a inner join ABCD.INCOME_&age0 AS b

         ON    a.ACT_NO=b.ACCOUNT_NUMBER

         WHERE b.STATUS^="CLOSED";

        

     CREATE TABLE OUR_age0_testing AS

    SELECT    a.*,

          b.LOAN_LIMIT,

          b.DEPOSIT,

          "&age0" as year_month

    FROM        Table1 /* Using Table1 as a replacement to the original In-Line Query */

     INNER JOIN ABCD.EXPENSES_&age0 AS b

         ON a.ACT_NO=b.ACCOUNT_NUMBER;

QUIT;

Thanks,

Ahmed

Super Contributor
Posts: 338

Re: Splitting the compacted SQL into simple two pieces?

Hi Ahmed,

Thank you for your help.

Miris

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 220 views
  • 0 likes
  • 2 in conversation