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

Esteemed Advisers:

I developed 6 SAS programs using SAS Studio that I execute sequentially to achieve the desired result. I would like to combine these six into a single code. Do I have to copy/paste all six into a single code or is it possible to somehow "call" them sequentially, as if they were stand-alone subroutines?

Thanks in advance for your help,

Gene

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Short smart-Alec answer: Yes

 

Details as to what the code looks like may be needed. Depending on what you are actually doing it may be possible to combine data step code into one data step. Maybe.

The %include statement will bring code from an external SAS file. Dummy example:

%include "c:\somefolder\mysasprog1.sas";

would call the code in the Mysasprog1 program file when encountered. There are other ways to use %include to reference the file but this is the basic approach. Make sure that any path starts at a drive or disk mount that is seen by the system running SAS which can get tricky with server versions.

As will anything related to computers there are restrictions such as %include follows a completed statement (i.e. ends with ; )  and NOT following a Cards or Datalines statement directly.

 

Calling specific code as desired might be macro coding where you compile a macro and then use the code where needed if it may execute in different order sometimes.

View solution in original post

3 REPLIES 3
ballardw
Super User

Short smart-Alec answer: Yes

 

Details as to what the code looks like may be needed. Depending on what you are actually doing it may be possible to combine data step code into one data step. Maybe.

The %include statement will bring code from an external SAS file. Dummy example:

%include "c:\somefolder\mysasprog1.sas";

would call the code in the Mysasprog1 program file when encountered. There are other ways to use %include to reference the file but this is the basic approach. Make sure that any path starts at a drive or disk mount that is seen by the system running SAS which can get tricky with server versions.

As will anything related to computers there are restrictions such as %include follows a completed statement (i.e. ends with ; )  and NOT following a Cards or Datalines statement directly.

 

Calling specific code as desired might be macro coding where you compile a macro and then use the code where needed if it may execute in different order sometimes.

genemroz
Quartz | Level 8
Thanks (!) to both responders. This worked perfectly. I was able to get the correct paths by opening the File Properties of each SAS code and copying the Location found therein into the %include statement.

Gene
PaigeMiller
Diamond | Level 26

Yes, you can create what I call a "batch file" even though it is SAS code. Example:

 

%include "full_path_to_file1.sas";
%include "full_path_to_file2.sas";
...
%include "full_path_to_file6.sas";
--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 629 views
  • 0 likes
  • 3 in conversation