f



Reusing code from SAS Program in another SAS Program

I write SAS programs on the Mainframe.  I have several programming
steps in multiple programs that use the same IF statements, for
example.

Maintenance is getting to be a problem because I may have to make the
same code change in 50 different programs.

I would like to write the If statement only once and read it into the
appropriate data steps of the various programs.

If someone could give me help on how I could do this, it would be
appreciated.

0
kmccall00 (1)
5/20/2005 10:23:07 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

3 Replies
729 Views

Similar Articles

[PageSpeed] 31

Keith -

Store your code snippets in a PDS and then %include into your programs.

For example this program includes a format called "$REGCRT" that I've stored
in the PDS DSCHEER.PROD.RUN.FORMATS($REGCRT):

//LOOKUP    JOB (DSDBX0000T,DS80,20,5,0),'CHOATE 654-2160',TIME=1,
//             USER=DSPAULC,MSGCLASS=X,NOTIFY=DSPAULC
//GOSAS    EXEC HWSAS
//SYSIN    DD *

OPTIONS PS=2000 LS=80;

LIBNAME  VENDOR 'DS.SYS.WORK.VENDOR.PANEL'   DISP=SHR;
FILENAME FMT    'DSCHEER.PROD.RUN.FORMATS'   DISP=SHR;
%INC FMT($REGCRT);

DATA LOOKUP;
  RETAIN SENDDATE VENDRC RCNAME VENDOR NAME
         ADDR1 ADDR2 ADDR3 ZIP PHONENUM
         INVADDR1 INVADDR2 INVZIP;
  SET VENDOR.PANEL;
  WHERE VENDOR IN ('HV0010' 'HV0011');
  RCNAME=PUT(VENDRC,$REGCRT.);
  KEEP SENDDATE VENDRC RCNAME VENDOR NAME
       ADDR1 ADDR2 ADDR3 ZIP PHONENUM
       INVADDR1 INVADDR2 INVZIP;

PROC PRINT;

RUN; ENDSAS;


Since %INC is a macro you can put it anywhere in open code and it will read
the code snippet during compilation.

hth

Paul Choate
DDS Data Extraction
(916) 654-2160

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Keith
Sent: Friday, May 20, 2005 3:23 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Reusing code from SAS Program in another SAS Program

I write SAS programs on the Mainframe.  I have several programming
steps in multiple programs that use the same IF statements, for
example.

Maintenance is getting to be a problem because I may have to make the
same code change in 50 different programs.

I would like to write the If statement only once and read it into the
appropriate data steps of the various programs.

If someone could give me help on how I could do this, it would be
appreciated.
0
pchoate (2538)
5/20/2005 10:44:10 PM
Keith,

You have two choices:

1st.:  create macros containing your if statements and store them either in
a user or public macro library.

2nd.:  Create text files contaiing your if statements save them in a PDS and
%include them in your program.



Toby Dunn




From: Keith <kmccall00@CHARTER.NET>
Reply-To: Keith <kmccall00@CHARTER.NET>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Reusing code from SAS Program in another SAS Program
Date: Fri, 20 May 2005 15:23:07 -0700
I write SAS programs on the Mainframe.  I have several programming
steps in multiple programs that use the same IF statements, for
example.

Maintenance is getting to be a problem because I may have to make the
same code change in 50 different programs.

I would like to write the If statement only once and read it into the
appropriate data steps of the various programs.

If someone could give me help on how I could do this, it would be
appreciated.
0
tobydunn (6020)
5/21/2005 2:18:36 AM
Hi Keith,
is it exactly the same code (a) or only the same structure but with different variable names in it (b) ?

(a) you may save the "IF code" in a separate member (let's say IFcode) and simply %INCLUDE that
    member within
    your various data stes.
    FILENAME xxx
    FILENAME xxx 'a.b.c.' DISP=shr;

    DATA ...
     SET ...
     %INCLUDE xxx(IFcode);
    run;

(b) you could use the same technique but with macro logic in order to set the variable names
    dynamically before including IFcode

does this help ?

Regards Roland

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Keith
Sent: Saturday, May 21, 2005 12:23 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Reusing code from SAS Program in another SAS Program

I write SAS programs on the Mainframe.  I have several programming
steps in multiple programs that use the same IF statements, for
example.

Maintenance is getting to be a problem because I may have to make the
same code change in 50 different programs.

I would like to write the If statement only once and read it into the
appropriate data steps of the various programs.

If someone could give me help on how I could do this, it would be
appreciated.
0
5/21/2005 9:44:58 AM
Reply: