DATA Step, Macro, Functions and more

Rerun the middle section to end of the program before program finishes running

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Rerun the middle section to end of the program before program finishes running

If I want to run a program all the way through and before the program finishes running, have it rerun the middle section to the end of the program one more time, how would I do that?


Accepted Solutions
Solution
‎05-08-2014 04:03 AM
Super User
Super User
Posts: 7,401

Re: Rerun the middle section to end of the program before program finishes running

Hi,

Hope that helped.  Just to clarify what I meant by popping a macro/mend around the code which I didn't explain above.  Use something like the below:

/* This code to run once */

...

...

...

%macro Code_to_run_twice();

     ...

     ...

     ...

%mend Code_to_run_twice;

%Code_to_run_twice;

%Code_to_run_twice;

View solution in original post


All Replies
Super User
Super User
Posts: 7,401

Re: Rerun the middle section to end of the program before program finishes running

Errrm, you can't.  Once a program is submitted then it runs through to the end.  You can cancel submitted programs.  Could you define in more detail why you would want to do this?  If the second half or your program needs to run twice, why not just pop a macro and mend around the code and call the macro twice?

Or highlight the first part of the code, execute that, then highlight the second part, run that, then submit it again.

Occasional Contributor
Posts: 13

Re: Rerun the middle section to end of the program before program finishes running

A part of the program I run twice.  I run the program all the way through, then immediately rerun a section of the program. This corrects the underlying data due to errors people make when they make changes.  Errors include improper end dates (end dated before month end) or reassignments to other groups. 

Hopefully I’m explaining this okay. I’m pretty new to this to using SAS. 

Super User
Super User
Posts: 7,401

Re: Rerun the middle section to end of the program before program finishes running

Ah, so you are doing some data cleaning, then some further operations on the clean data.  I would then suggest that you would be better served setting up a staging process for this:

Raw Data -> Data Cleaning Checks -> Clean Data

Clean Data -> Output Programs

You may find yourself having difficulties latter on with things changing, lack of audit trail etc.

You can still do it in one program, just create temporary datasets:

data processed_data;

     set raw_data;

     do some edit checking/re-assignment;

run;

proc report processed_data;

     ...

run;

If you need further info or help, post some test data and the parts of your code you are re-running and we could suggest further items.  Am not in office now, so would be tomorrow.

Solution
‎05-08-2014 04:03 AM
Super User
Super User
Posts: 7,401

Re: Rerun the middle section to end of the program before program finishes running

Hi,

Hope that helped.  Just to clarify what I meant by popping a macro/mend around the code which I didn't explain above.  Use something like the below:

/* This code to run once */

...

...

...

%macro Code_to_run_twice();

     ...

     ...

     ...

%mend Code_to_run_twice;

%Code_to_run_twice;

%Code_to_run_twice;

Occasional Contributor
Posts: 13

Re: Rerun the middle section to end of the program before program finishes running

I tried both responses and they both worked. Just so I didn't have to divide the program I used the %macro %mend.

Thank you both!

Valued Guide
Posts: 3,208

Re: Rerun the middle section to end of the program before program finishes running

divide you code into several parts storing the in segegrated locations.

Having the program run use the %include to call (bring the code) into running. Needed to run twice, do the %include twice.

---->-- ja karman --<-----
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 357 views
  • 3 likes
  • 3 in conversation