BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Guys

Here I am trying to compare dataset are identical or not in a library using %sysinfo option  but below code not give correct result

data first;
set sashelp.class;
run;

data second;
set sashelp.cars;
run;

data check_dsn;
if &sysinfo.=1 then put "The two data sets are not identical";
else put "The two data sets are identical ";
run;

 

4 REPLIES 4
Kurt_Bremser
Super User

From the documentation of SYSINFO:

 

SYSINFO Automatic Macro Variable

Contains return codes provided by some SAS procedures.

Type: Automatic macro variable (read only)

Details

Values of SYSINFO are described with the procedures that use it. You can use the value of SYSINFO as a condition for determining further action to take or parts of a SAS program to execute.

For example, PROC COMPARE, which compares two data sets, uses SYSINFO to store a value that provides information about the result of the comparison.

 

(emphasis added)

Two separate data steps do not compare anything.

maguiremq
SAS Super FREQ

If you're comparing two different data sets, you have to make sure they share something in common like an ID.

 

data first;
	set sashelp.class;
run;

data second;
	set sashelp.cars;
run;

proc compare
	data = first
	compare = second;
run;

Look into PROC COMPARE -- it's a SAS procedure that does exactly what you want without having to code it. Note that I just did a raw compare of both files -- it found one variable in common (weight), but it has no substantive significance (comparing car weights to school childrens' weights).

 

There are many statements in PROC COMPARE that allow you to select variables, identify observations, etc. You can create datasets from the PROC COMPARE procedure too.

 

There are many ways to do this, but just go with what SAS has already done for you.

 

 

SASKiwi
PROC Star

To make use of SYSINFO you first need to run PROC COMPARE then immediately following you can check it:

proc compare base = base
                      comp = compare
                     ;
run;

%let rc = &sysinfo;

data _null_;
 %* Test for data set label ;
   if &rc = '1'b then
      put "<<<< &table.: Data sets have different labels";
 %* Test for data set types ;
   if &rc = '1.'b then
      put "<<<< &table.: Data set types differ";
 %* Test for label ;
   if &rc = '1.....'b then
      put "<<<< &table.: Variable has different label";
 %* Test for base observation ;
   if &rc = '1......'b then
      put "<<<< &table.: Base data set has observation not in comparison data set";
 %* Test for length ;
   if &rc = '1....'b then
      put "<<<< &table.: Variable has different lengths between the base data set and the comparison data set";
 %* Variable in base data set not in compare data set;
   if &rc ='1..........'b then 
      put "<<<< &table.: Variable in base data set not found in comparison data set";
 %* Comparison data set has variable not in base data set ;
   if &rc = '1...........'b then
      put "<<<< &table.: Comparison data set has variable not contained in the base data set";
 %* Test for values ;
   if &rc = '1............'b then
      put "<<<< &table.: A value comparison was unequal";
 %* Conflicting variable types;
   if &rc ='1.............'b then
      put "<<<< &table.: Conflicting variable types between the two data sets being compared";
run;

 

ballardw
Super User

Identical structure? Identical contents? Identical contents including current record order? or some other "identical"?

 

Proc Compare will report on number, names and  values of variables, but is sort order dependent on reporting differences in values.

You can run this code to see the possible effect of sort order:

proc sort data=sashelp.class out=work.class1;
   by name ;
run;

proc sort data=sashelp.class out=work.class2;
   by descending name ;
run;

proc compare base=work.class1 compare=work.class2;
run;

You should have the SASHELP.Class data set available as part of your install. Notice that since the data set has 19 records (an odd number) the middle of the sort on a single variable with unique values like Name in this set, makes the middle record, the 10th observation the same. So you see 18 of 19 records different.

 

You can look at the documentation for the procedure to see what additional options may be of interest.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1nwxbchh5hpu1n1h28kmici2awd.htm

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 441 views
  • 4 likes
  • 5 in conversation