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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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