To start, review your code for unnecessary DATA steps, for starters the NUM assignment can be coded in the initial DATA step.
And are you certain the code works, as you have posted - what is this stmt doing (several statements are missing trailing semi-colons as well):
where num=#
Recommend setting FULLSTIMER option and interrogate each step, either PROC or DATA type. Isolate steps that may be consolidated into prior steps. Investigate using SAS views, where applicable.
Scott Barry
SBBWorks, Inc.