BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
theponcer
Quartz | Level 8

 

I have used logic similar to the below several times to run large processes that are split up into smaller sub-programs. However, I am running into an unusual problem - for some reason, program 2 doesn't seem to run. Program 3 uses a table that gets written to the work drive in program 2, but I keep getting an error saying that the table cannot be found. When I check the log, I see that the program text skips from the end of program 1 to the beginning of program 3. What can I do to test what might be going wrong here?


*****INPUTS*****;
%let program_path = \\xxx\Programs\Production;
*Step 1; %let run1 = Y; %let path1 = &program_path.\(1) Step One.sas; *Step 1a; %let run_1a = Y; %let path1a = &program_path.\(1a) Step 1a; *Step 2; %let run2 = Y; %let path2 = &program_path.\(2) Step 2.sas; *Step 3; %let run3 = Y; %let path3 = &program_path.\(3) Step 3.sas; *Step 4; %let run4 = Y; %let path4 = &program_path.\(4) Step 4.sas; *Step 5; %let run5 = Y; %let path5 = &program_path.\Step 5.sas; *Step 6; %let run6 = Y; %let path6 = &program_path.\Step 6.sas; *****CODE*****; *Run programs; data _null_; %sysfunc(ifc(&run_1a. = Y, %include "&path1a.",)); %sysfunc(ifc(&run1. = Y, %include "&path1.",)); %sysfunc(ifc(&run2. = Y, %include "&path2.",)); %sysfunc(ifc(&run3. = Y, %include "&path3.",)); %sysfunc(ifc(&run4. = Y, %include "&path4.",)); %sysfunc(ifc(&run5. = Y, %include "&path5.",)); %sysfunc(ifc(&run6. = Y, %include "&path6.",)); run;

 

 

1 ACCEPTED SOLUTION
8 REPLIES 8
Reeza
Super User

Anything in any of those programs use a RSUBMIT?

Can you save the file to a non-work space instead of work?

theponcer
Quartz | Level 8

Awesome, that seems to solve my problem. The only question I have is that it also throws an unexpected error - see my (edited) log below. The log says that nested if statements in open code are not supported. However, my if statements are not nested. Any ideas as to what is throwing this error? My (edited) log is below:

 

685        %if &run_1a. = Y %then %do; %include "&path1a."; %end;
SYMBOLGEN:  Macro variable PATH1A resolves to \\xxx\Programs\Testing\(1a) Program 1a.sas
NOTE: %INCLUDE (level 1) file \\xxx\Programs\Testing\(1a) Program 1a.sas
      (1a) Program 1a.sas is file \\xxx\Programs\Testing\(1a) Program 1a.sas.

…

NOTE: %INCLUDE (level 1) ending.

781        %if &run1. = Y %then %do; %include "&path1."; %end;
SYMBOLGEN:  Macro variable RUN1 resolves to Y
SYMBOLGEN:  Macro variable PATH1 resolves to \\xxx\Programs\Testing\(1) Program 1.sas
NOTE: %INCLUDE (level 1) file \\xxx\Programs\Testing\(1) Program 1.sas is file \\xxx\Programs\Testing\(1) Program 1.sas.

…

NOTE: %INCLUDE (level 1) ending.
ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.
ERROR: Skipping to next %END statement.

SYMBOLGEN:  Macro variable PATH2 resolves to \\xxx\Programs\Testing \(2) Import Drug Lists.sas
942        %if &run2. = Y %then %do; %include "&path2."; %end;
NOTE: %INCLUDE (level 1) file \\xxx\Programs\Testing\(2) 
      Import Drug Lists.sas is file \\xxx\Programs\Testing\(2) Import Drug Lists.sas.

…


NOTE: %INCLUDE (level 1) ending.
998        %if &run3. = Y %then %do; %include "&path3."; %end;
SYMBOLGEN:  Macro variable RUN3 resolves to Y
SYMBOLGEN:  Macro variable PATH3 resolves to \\xxx\Programs\Testing\(3) Adherence Calcs.sas
NOTE: %INCLUDE (level 1) file \\xxx\Programs\Testing\(3) 
      Adherence Calcs.sas is file \\xxx\Programs\Testing\(3) 
      Adherence Calcs.sas.
theponcer
Quartz | Level 8

Awesome, thank you!

mkeintz
PROC Star

@theponcer wrote:

Awesome, that seems to solve my problem. The only question I have is that it also throws an unexpected error - see my (edited) log below. The log says that nested if statements in open code are not supported. However, my if statements are not nested. Any ideas as to what is throwing this error? My (edited) log is below:

Are your %INCLUDEd programs totally devoid of %IF statements?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

Do any of your %include program files create or modify variables named Run or Path in any form?

 

Characters like ( and ) in file paths can be problematic when resolved in some macro uses.

You may also have to count spaces in your paths and look at your file system very carefully to make sure the number of spaces matches, one of the reasons spaces are often recommended for exclusion in file paths.

 

And a relatively recent development with macro variables, paths and "cloud" storage like OneDrive is that a space at the front of a path may cause issues.

I had to change a lot of path code that had statements like: %let path = d:\folder\subfolder to be %let path =d:\folder\subfolder  because the OneDrive layer used that space before the drive for something and could not find my paths.

theponcer
Quartz | Level 8

I ran across this issue again but was able to solve it this time. The real issue is that I had comments at the end of my code that were not closed. This caused the next %include statement to malfunction. If you are having this problem, find the first program that is not running and then check to see if there are comments at the end of the previous program. I was able to solve this by adding an extraneous run statement after the include. You could also just move or correctly close the comments! 

 

This thread was what got me to the finish line: https://communities.sas.com/t5/SAS-Procedures/include-stops-need-help-please/td-p/25572

 

%if &run_weekly. = Y %then %do; %include "&path1a."; %end; run;
%if &run1. = Y %then %do; %include "&path1."; run; %end;
%if &run2. = Y %then %do; %include "&path2."; run; %end;
%if &run3. = Y %then %do; %include "&path3."; run; %end;
%if &run4. = Y %then %do; %include "&path4."; run; %end;
%if &run5. = Y %then %do; %include "&path5."; run; %end;
%if &run6. = Y %then %do; %include "&path6."; run; %end;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1529 views
  • 0 likes
  • 5 in conversation