The SAS Output Delivery System and reporting techniques

Compare one run of a program to the last time program ran for changes

Reply
Contributor
Posts: 58

Compare one run of a program to the last time program ran for changes

I am not sure how to word this but I have a series of programs that run to create a final data file. I will be running this data file on a weekly basis. I have to compare the current data file to the last data file ran to see if any new groups have been added (the field Is called Group_Number.) I need to see if any new groups have been added since the last time I ran the data. If you can be specific as to how to do this, that would be so helpful as I am basically new to SAS.
N/A
Posts: 0

Re: Compare one run of a program to the last time program ran for changes

once the new file (new.dataset ?) is created, create an output summary of "groups", perhaps like[pre]
proc summary data = new.dataset missing nway ;
class group_number ;
output out= data.groups_&sysdate( keep= group_number _freq_ ) ;
run;[/pre]
Then you have frequency counts in each group to compare with the previous run, like: [pre]
data changes ;
merge data.latest( keep= group_number _freq_ rename=(_freq_=old_ct ))
data.groups_&sysdate( in= new rename=( _freq_= ct_&sysdate) ) ;
by group_number ;
run; [/pre]
This provides old and new frequencies to support a comparison report, like:[pre]
proc print data= changes ;
title "file load group changes report" ;
title3 " only new Groups and ceasing Groups are shown ";
where not ( ct_&sysdate and old_ct ) ; * = not present in both files;
run;[/pre]
Of course, you have to prepare for the next comparison by placing the latest summary as the "latest" dataset, like: [pre]
data data.latest ;
set data.groups_&sysdate ;
label _freq_ = "counts &sysdate" ;
run;[/pre]
Clearly you have created a second copy of the data, but it makes the process straightforward to run regularly - special situations like re-runs, or comparisons over longer periods, or presentation of growth trends over time are supported too, but without automation ...............

Good Luck
PeterC
Frequent Contributor
Posts: 95

Re: Compare one run of a program to the last time program ran for changes

The previous post is good if you want to know about any changes to the groups, but if you just want the IDs of the newly added groups, you could use some simpler code. Here's an example:

proc sort data=work.old out=work.old_groups nodupkey; by group_number; run;
proc sort data=work.new out=work.new_groups nodupkey; by group_number; run;

data work.diff;
merge work.old_groups (in=a) work.new_groups (in=b);
by group_number;
if b and not a;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 125 views
  • 0 likes
  • 3 in conversation