Search code examples
sqlif-statementsasproc-sqlenterprise-guide

SAS EG SQL create a table named "SUCCESS" if 2 counts are identical


I have two counts in my process, they should give the same result.

One is before a batch of queries, one is after, I want to make sure that the join operation haven't added or removed rows.

Right now I check these counts manually but I'd like a visual indicator that things went fine.

Thus I had the idea of writing a program that wille create an empty table named "SUCCESS" if these counts are equal, or a table named "FAILURE" if they're not.

Can you help me design the query that would achieve that ?

Here's what I have (not working obviously):

PROC SQL;
IF (SELECT count FROM WORK.count1) = (SELECT count FROM WORK.count2)
    CREATE TABLE WORK.SUCCESS
ELSE
    CREATE TABLE WORK.FAILURE
END
QUIT;

count1 and count2 are two tables that contain each a field named count, and one row with the value to be tested


Solution

  • I wouldn't use PROC SQL to do something like that.

    data _null_;
      merge count1(rename=(count=count1)) count2(rename=(count=count2));
      if count1 ne count2 then call execute('data failure;run;');
      else call execute('data success;run;');
    run;
    

    Wouldn't it just be better to have the job to FAIL if the counts are different? Not sure if this works properly in Enterprise Guide, but in a batch run you could just conditionally run the ABORT ABEND statement.

    data _null_;
      merge count1(rename=(count=count1)) count2(rename=(count=count2));
      if count1 ne count2 then abort abend ;
    run;