BookmarkSubscribeRSS Feed
Grandhi4
Calcite | Level 5

Hi,

If i have a Two datasets one has 10 variables and other one has 10 variables or may be less or more

How to compare the datasets variables names and properties (Char, numeric, format, informat, length....) if both same then it should come TRUE or If it's not same any one then it should come ERROR.....how to  do can any one help on this...

Thanks,

Smiley Happy

6 REPLIES 6
LinusH
Tourmaline | Level 20

You should start with PROC COMPARE, and taket it from there...

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p1l5iwaf47ma83n1euxxp...

Data never sleeps
Grandhi4
Calcite | Level 5

Thanks LinusH,  But i'm looking in Macro code not PROC

LinusH
Tourmaline | Level 20

Why?

Data never sleeps
Grandhi4
Calcite | Level 5

req is macro

LinusH
Tourmaline | Level 20

?

"Macro" meaning what?. Can't you embed PROC's in the macro?

Otherwise, you can use SAS File I/O functions, which can call from %sysfunc. But I believe thatwill generate some more coding...

Data never sleeps
Patrick
Opal | Level 21

Below code should give you a start. Now it's only about wrapping a macro around the code (if you must) where you pass libname and tablenames.

data have1;
   set sashelp.class;
run;

data have2;
   set sashelp.class;
/*   label sex='Different from have1';*/
run;


%let Same_Flg=0;
proc sql noprint;
   select count(*) into :Same_Flg
   from
      (
      select name, type, length, npos, varnum,label,format,informat,notnull,precision,transcode
         from dictionary.columns where libname='WORK' and memname='HAVE1'
      outer union corr
      select name, type, length, npos, varnum,label,format,informat,notnull,precision,transcode
         from dictionary.columns where libname='WORK' and memname='HAVE2'
      )
      group by name, type, length, npos, varnum,label,format,informat,notnull,precision,transcode
      having count(*) ne 2
   ;
quit;

%let Same_Flg=%eval(&Same_Flg = 0);

/* Same_Flg: 1 if no differences, 0 if differences */
%put XXXX &Same_Flg;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1251 views
  • 0 likes
  • 3 in conversation