Hi,
I have four-ish SAS steps that i want to repeat until no more records are deleted in the last step.
I was thinking do/until sounded right, but i have never used it before, so i wasn't sure. So keep in mind, while i'm playing around with writing stuff, nothing is currently running. This is pretty much abstract theory so far.
But i was thinking:
%macro
%do %until (var=0);
blah - frequency
blah - second separate data step
blah - third separate data step
blah - other data step
blah - check dictionary tables for record counts
var=[record counts]-[record counts]
%end;
%mend;
So in step 5, it was grabbing the nobs from the dictionary tables, so could tell whether any records were deleted in step 4, and have a tangible count of it. If no records were deleted, stop processing, if records were deleted, process the cycle again.
But then i realized i needed an iterative counter to track the datasets through each cycle and then i realized i had to write in a split path at the top so that first time through it would take one dataset to start, but second+ it would take the end table from the previous time through, and now i'm wondering if this is even the best way to do it.
What do you guys think?
Thanks.
I did end up getting this to work with a do/until and built in counter, but the code is too long to post here. If someone wants to send me a message with a question, feel free. But i don't know how to delete posts, so i'm going to use this one as the solution. 🙂
Since the question is conceptual only at this point, here are some gut reactions.
First, since the possibility of an infinite loop exists, I would be very careful to make sure the program ends (regardless of the final coding techniques used).
Second, I would reuse the same data set name until SAS is sick of it. For example, capture the number of records after step 3 into a macro variable &BEFORE, then capture the number of records after step 4 into &AFTER. See if &BEFORE=&AFTER. Then you don't need to count number of iterations, and you don't need to change the data set names each time.
I did end up getting this to work with a do/until and built in counter, but the code is too long to post here. If someone wants to send me a message with a question, feel free. But i don't know how to delete posts, so i'm going to use this one as the solution. 🙂
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: