I have several large datasets that are iteratively processed by several sas programs, some of which I am not the primary programmer for. I'm trying to brainstorm an easy data driven way to hook into those programs and record the names of variables with at least one changed observation (independent of sort order). I'm hoping sas tracks this somewhere behind the scenes and I can write a macro to tap into it without placing too much of a burden on the other programmers.
I currently can track input variables into each program, and I can track when new variables are being created by diffing proc summaries before and after the program is ran, but obviously checking for changed values is much harder and it would be very useful to track dependencies between these chains of programs.
Thanks,
Building on @Reeza, here's an example of how to output results that are different for some data sets using PROC COMPARE. You may need to tinker with some of the options here (if you only want the compare value, drop the outbase option) , but I think it shows what PROC COMPARE can do. It's a procedure I used heavily in a previous job. Edit: looking at your question again, I'm not sure if I totally answered the question. You want to know the value that differs and then return the variable name? It also assumes a sort, but you can avoid this with an ID statement instead of the BY statement, but it will send a warning about duplicate values if you have them in your data set. Also, if you want to see the report that PROC COMPARE produces, remove the NOPRINT option.
data have;
input id value;
datalines;
1 2
1 3
1 4
1 5
1 6
;
data have_2;
input id value;
datalines;
1 2
1 3
1 4
1 5
1 7
;
proc compare out = work.want outnoequal outbase outcomp noprint
base = have
compare = have_2;
by id;
var value;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.