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!
Thanks!
Mike
SAS code name: NEED
****NEED.SAS****;
/*Begin of NEED.sas*/
/*main program part*/
call sub code sub1;
call sub code sub2;
call sub code sub3;
.........
/*sub code definition part*/
sub1
proc print data=sashelp.class;
run;
end sub1;
sub2
data one;
x=1;
run;
end sub2;
sub3
proc sql noprint;
create table two as
select *
from sashelp.class
;
quit;
end sub3;
/*End of NEED.SAS*/
looks like a '%Macro' or '%include' or 'call execute' sort of implementation.
Haikuo
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.
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;
%sub1;
%sub2;
...
%mend main;
%macro sub1;
...
%mend sub1;
%macro sub2;
...
%mend sub2;
%main;
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');
%sub1;
%sub2;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: