07-18-2012 05:13 PM
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 NEED.sas*/
/*main program part*/
call sub code sub1;
call sub code sub2;
call sub code sub3;
/*sub code definition part*/
proc print data=sashelp.class;
proc sql noprint;
create table two as
/*End of NEED.SAS*/
07-18-2012 06:22 PM
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.
07-18-2012 06:59 PM
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.
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: