☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-15-2024 04:35 PM
(1020 views)
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)?
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Paige Miller
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;