Help using Base SAS procedures

Is this code structure available for SAS?

Reply
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!

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*/

Respected Advisor
Posts: 3,156

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.

Haikuo

Super User
Posts: 19,770

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: 7,039

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;

  %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;

Ask a Question
Discussion stats
  • 3 replies
  • 159 views
  • 0 likes
  • 4 in conversation