BookmarkSubscribeRSS Feed
lloraine
Calcite | Level 5
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.
2 REPLIES 2
deleted_user
Not applicable
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
1162
Calcite | Level 5
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 614 views
  • 0 likes
  • 3 in conversation