BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

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

3 REPLIES 3
Haikuo
Onyx | Level 15

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

Haikuo

Reeza
Super User

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.

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 652 views
  • 0 likes
  • 4 in conversation