BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RolandTower
Calcite | Level 5

Hi everyone

I have the following code that creates two datasets - _TEST123 has 3 variables, and _TEST12 has 2 variables. 

A PROC COMPARE with _TEST123 as the BASE dataset and _TEST12 as the COMPARE dataset gives a return code of 1024, indicating that the "Base dataset has variable not in comparison". 

A PROC COMPARE with _TEST12 as the BASE dataset and _TEST123 as the COMPARE dataset gives a return code of 0, indicating no issues, even though the actual PROC COMPARE output indicates that the variable X3 is in the COMPARE dataset but not the BASE dataset.   The return code of 0 is not the value that what I would expect.

I believe that the reason the return code is equal to 0 in the second compare is that I am using the VAR statement with X:, which gets SAS to create the list of variables from those present in both the BASE and COMPARE dataset or in the BASE dataset only (this comes from the VAR statement documentation).  This then means that X3 gets omitted by SAS from the VAR statement and hence the return code of 0 is obtained.  If you drop the VAR statement from the PROC COMPARE then you get the results I would expect, which is a return code of 2048 for the second compare.

So to my question:  Is it wrong to expect the second PROC COMPARE step below, with the VAR statement in place, to give a return code of 2048 (i.e. is the return code of 0 what I should expect)?  I am pretty sure I know why I get a result of 0, but I don't think that SAS should be giving me that result.

 

/* data creation              */

data _test123;

     do subjid = 1 to 10;

          x1   = 1;

          x2   = 2 + subjid;

          x3   = 3;

          output;

     end;

run;

data _test12;

     do subjid = 1 to 10;

          x1   = 1;

          x2   = 2 + subjid;

          output;

     end;

run;

/* COMPARE #1                */

proc compare base=_test123 compare=_test12 out=_outnoequal outnoequal method=absolute listall;

     id subjid;

     var x:;

run;

%put PROC COMPARE return code = &sysinfo;  /* returns the expected value of 1024 */

/* COMPARE #2                */

proc compare base=_test12 compare=_test123 out=_outnoequal outnoequal method=absolute listall;

     id subjid;

     var x:;

run;

%put PROC COMPARE return code = &sysinfo;  /* returns a value of 0 */

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

> Is it wrong to expect the second PROC COMPARE step below, with the VAR statement in place, to give a return code of 2048 (i.e. is the return code of 0 what I should expect)? 

 

You specifically supply a list of variables. So SAS only compares these variables.

Since you let SAS build that list by using an abbreviated syntax it uses the BASE table for that purpose.

The same would happen if you used another abbreviated syntax, for example _numeric_ .

 

Now the question is: Should SAS use both tables to build that list?

I didn't find any documentation about this, but the observed behaviour makes sense to me.

The base table is the reference. The other table is compared to that reference.

Building the list from that reference rather than any other source seems perfectly coherent.

 

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

> Is it wrong to expect the second PROC COMPARE step below, with the VAR statement in place, to give a return code of 2048 (i.e. is the return code of 0 what I should expect)? 

 

You specifically supply a list of variables. So SAS only compares these variables.

Since you let SAS build that list by using an abbreviated syntax it uses the BASE table for that purpose.

The same would happen if you used another abbreviated syntax, for example _numeric_ .

 

Now the question is: Should SAS use both tables to build that list?

I didn't find any documentation about this, but the observed behaviour makes sense to me.

The base table is the reference. The other table is compared to that reference.

Building the list from that reference rather than any other source seems perfectly coherent.

 

RolandTower
Calcite | Level 5
Hi Chris

Thanks for response. I agree that the BASE table is the reference and I accept that this is how SAS constructs the list of variables when the VAR statement is specified. I suppose my question, probably unanswerable, is how does SAS construct the list of variables when the VAR statement is not specified and why does this differ when the abbreviated syntax is used?
ChrisNZ
Tourmaline | Level 20

By nor specifying VAR, you request that SAS compare all variables that can be found.

No list means no restriction: everything is compared. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 715 views
  • 3 likes
  • 2 in conversation