BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Justin9
Obsidian | Level 7

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)?

 

Justin9_0-1708033157458.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Justin9
Obsidian | Level 7
Thanks for your help!
data_null__
Jade | Level 19

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;

Capture.PNG

SAS Innovate 2025: Register Now

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!

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
  • 736 views
  • 3 likes
  • 3 in conversation