Last active
November 30, 2017 17:29
-
-
Save statgeek/e0b98c4627aa31a567e5 to your computer and use it in GitHub Desktop.
SAS_compare_dataset_variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro compare_data(base=, compare=); | |
proc sql noprint; | |
create table base_in as | |
select name | |
from sashelp.vcolumn | |
where libname=upper(scan("&base", 1, ".")) | |
and memname=upper(scan("&base", 2, ".")) | |
order by varnum; | |
quit; | |
proc sql noprint; | |
create table compare_in as | |
select name | |
from sashelp.vcolumn | |
where libname=upper(scan("&compare", 1, ".")) | |
and memname=upper(scan("&compare", 2, ".")) | |
order by varnum; | |
quit; | |
proc sql; | |
create table comparison as | |
select a.name as base_var, b.name as compare_var, | |
case when missing(a.name) then catx("-", "Comparison dataset has extra variable", b.name) | |
when missing(b.name) then catx("-", "Comparison dataset is missing variable", a.name) | |
when a.name=b.name then "Variable in both datasets" | |
else "CHECKME" | |
end as comparison | |
from base_in as a | |
full join compare_in as b | |
on a.name=b.name; | |
quit; | |
data _null_; | |
set comparison; | |
if comparison not eq "Variable in both datasets" | |
then put "ERROR:" comparison; | |
run; | |
%mend; | |
/*example of calling macro*/ | |
data class; | |
set sashelp.class; | |
drop sex age; | |
weight2=weight*2; | |
run; | |
%compare_data(base=sashelp.class, compare=work.class); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment