LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 17 Dec 2002 17:16:11 -0500
Reply-To:     "Ed C." <sandrun@PRODIGY.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Ed C." <sandrun@PRODIGY.NET>
Subject:      Playtime: local and global macro variables

Hi SAS-L,

Here is fun code to test basic understanding of macro variables. I needed reminding about the concept of inheritance (is that the right word?). Ran it under Windows SAS v8.2.

Hope this informs or entertains.

Thanks!

Ed C

--------code------------------- --------code------------------- --------code-------------------

*---------------------------------------------------------------*; * program: test_localglobal.sas *; * author: ed cabanero (sandrun@prodigy.net) *; * date: 17Dec2002 *; * objective: verify understanding of inherited macro variables *; * input/output required: *; * none *; * description: *; * each macro calls the macro just above it and *; * displays information about macro variables *; * available for use within each call. *; *---------------------------------------------------------------*;

%macro calledf;

%put Step 4. Value from calledt is test3 = &test3;

%global test4; %let test4=final;

%put; %put Section 2. Return nth call to top level macro; %put %nrstr(Step 4. calledf -->); %put _user_;

%mend;

%macro calledt;

%put Step 3. Value from called is test2 = &test2;

%local test3a; %let test3=symbols; %let test3a=symbolsyeah;

%calledf;

%put %nrstr(Step 3. calledt -->); %put _user_;

%mend;

%macro called;

%put Step 2. Value from caller is test1 = &test1;

%let test2=123.45;

%calledt;

%put %nrstr(Step 2. called -->); %put _user_;

%mend;

%macro caller;

%put; %put Section 1. Begin top level macro to nth call; %put Step 1. Start the chain;

%let test1=be a character string;

%called;

%put %nrstr(Step 1. caller -->); %put _user_;

%mend;

%caller;

--------log-------------------- --------log-------------------- --------log--------------------

Section 1. Begin top level macro to nth call Step 1. Start the chain Step 2. Value from caller is test1 = be a character string Step 3. Value from called is test2 = 123.45 Step 4. Value from calledt is test3 = symbols

Section 2. Return nth call to top level macro Step 4. calledf --> CALLEDT TEST3 symbols CALLEDT TEST3A symbolsyeah CALLED TEST2 123.45 CALLER TEST1 be a character string GLOBAL TEST4 final Step 3. calledt --> CALLEDT TEST3 symbols CALLEDT TEST3A symbolsyeah CALLED TEST2 123.45 CALLER TEST1 be a character string GLOBAL TEST4 final Step 2. called --> CALLED TEST2 123.45 CALLER TEST1 be a character string GLOBAL TEST4 final Step 1. caller --> CALLER TEST1 be a character string GLOBAL TEST4 final


Back to: Top of message | Previous page | Main SAS-L page