Hi,
I have got two datasets and want to check that where a variable appears in both (can ignore if a variable just appears in one dataset), the variable type is the same in both to create something like the screenshot below. From there, there could be a created 'Match' variable to let me know if a variable has the same variable type ('Match') or if they are different ('No Match'). Can someone tell me the code that would be able to do this please (as there are likely to be over 500 variables to check)?
So, assuming the variable names are the same in both data sets
proc contents data=dataset1 noprint out=_contents1_;
run;
proc contents data=dataset2 noprint out=_contents2_;
run;
proc format;
value typef 1='Numeric' 2='Char';
run;
data compare;
length match $ 8;
merge _contents1_(rename=(type=type1)) _contents2_(rename=(type=type2));
by name;
if type1=type2 then match='Match';
else match='No Match';
format type1 type2 typef.;
run;
So, assuming the variable names are the same in both data sets
proc contents data=dataset1 noprint out=_contents1_;
run;
proc contents data=dataset2 noprint out=_contents2_;
run;
proc format;
value typef 1='Numeric' 2='Char';
run;
data compare;
length match $ 8;
merge _contents1_(rename=(type=type1)) _contents2_(rename=(type=type2));
by name;
if type1=type2 then match='Match';
else match='No Match';
format type1 type2 typef.;
run;
Proc compare has some nice reports related to the variables in the data being compared.
data class;
set sashelp.class;
length _age $8;
_age=left(vvalue(age));
drop age;
rename _age=Age;
run;
proc compare note
data=sashelp.classfit(obs=0)
compare=class(obs=0)
listvars novalues brief;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.