Help using Base SAS procedures

Is this code structure available for SAS?

Regular Contributor
Posts: 222

Is this code structure available for SAS?

Hello everyone,

I want create a SAS code with this structure: I am not sure whether there wis a method like this in SAS.

because if use sub code if the sub code part used repeatedly in one program will save lots of code space.

I know we can create  macros for these sub codes part,BUT a macro must be defined before use of it ,while a sub code could be put in any place of the program.(I have this idea from  other programming  language,I know SAS read dataset from top to bottom row by row,I hope SAS could read  program code in a more flexible way)

Any suggestion will be appreciate!



SAS code name: NEED


/*Begin of*/

/*main program part*/

call sub code sub1;

call sub code sub2;

call sub code sub3;


/*sub  code definition part*/


proc print data=sashelp.class;


end sub1;


data one;



end sub2;


proc sql noprint;

create table two as

select *

from sashelp.class



end sub3;

/*End of NEED.SAS*/

Respected Advisor
Posts: 3,167

Re: Is this code structure available for SAS?

Posted in reply to Mike_Davis

looks like a '%Macro' or '%include' or 'call execute' sort of implementation.


Super User
Posts: 23,659

Re: Is this code structure available for SAS?

Not easily.

SAS works a bit differently so its well worth learning how to deal with it efficiently rather than try and make it work other ways, in my opinion.

The %macro and %includes can get you pretty far in terms of automating projects.

Super User
Super User
Posts: 8,068

Re: Is this code structure available for SAS?

Posted in reply to Mike_Davis

Not sure what the advantage would be.  But to be able to do it exactly that way SAS would need to be a compiled language instead of an interpreted one.  You could structure your source that way in SCL since it needs to be compiled.

If you really wanted to create code in that form you could wrap the main routine in a macro and then call it at the bottom of the file after all the sub macros have been defined.  But I do not recommend it.

%macro main;




%mend main;

%macro sub1;


%mend sub1;

%macro sub2;


%mend sub2;


A more natural process would be to create autocall library for the subroutine macros. Create a separate file with each macro's definition and store them in a directory.  Then you main program could look like:

options sasautos=('mymacros');



Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation