Date: Thu, 9 Oct 2003 09:27:41 +0800
Reply-To: Zibao Zhang <zibaozhang@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Zibao Zhang <zibaozhang@HOTMAIL.COM>
Subject: Re: macro error
Content-Type: text/plain; charset="iso-8859-1"
Hi Rune,
The error is related to the scope the macro variables. the macro variables ant_arkiv, ant_sak and ant_dok is LOCAL macro variables, so they occure only in the macro count_datafiles. you can check it like this:
%count_datafiles; /*In invoke the macro*/
%put _user_; /*To display all macro variables user defined after the macro*/
you will find no macro variables mentioned above. so the macro test_datafiles can't reference the macro variables.
<But if you use %put in macro count_datafiles, they are there.>
There are two ways to modify it:
1) Declare the macro variables defined in macro count_datafiles as global one so the next macro can reference them:
%macro count_datafiles;
%global ant_arkiv, ant_sak and ant_dok;
proc sql noprint;
select count(*) into :ant_arkiv
from &bibl..arkiv;
<removed>
<You can delete them using %symdel to delete them after the next macro if you don't like them.>
2) Merge the two macros into one:
%macro merge_datafiles(bibl=);
proc sql noprint;
select count(*) into :ant_arkiv
from &bibl..arkiv;
select count(*) into :ant_sak
from &bibl..sak;
select count(*) into :ant_dok
from &bibl..dok;
quit;
data &bibl..kompl_antall;
ARKIV = &ant_arkiv;
SAK = &ant_sak;
DOK = &ant_dok;
run;
%mend merge_datafiles;
Hope this helps,
============
Kind Regards,
Zibao Zhang, MD
----- Original Message -----
From: "Rune Runnestoe" <rune@FASTLANE.NO>
Newsgroups: bit.listserv.sas-l
To: <SAS-L@LISTSERV.UGA.EDU>
Sent: Thursday, October 09, 2003 4:12 AM
Subject: macro error
> The code goes like this:
>
> %macro count_datafiles;
> proc sql noprint;
> select count(*) into :ant_arkiv
> from &bibl..arkiv;
>
> select count(*) into :ant_sak
> from &bibl..sak;
>
> select count(*) into :ant_dok
> from &bibl..dok;
> quit;
> %mend;
>
> %macro test_datafiles;
> *Macro to test the number of records in the datasets;
>
> %count_datafiles;
> data &bibl..kompl_antall;
> ARKIV = &ant_arkiv;
> SAK = &ant_sak;
> DOK = &ant_dok;
> run;
> %mend;
>
> %test_datafiles;
>
> ---------------------------------------------
> The message from the log is as follows:
>
>
> MPRINT(COUNT_DATAFILES): proc sql noprint;
> SYMBOLGEN: Macro variable BIBL resolves to SAHA8800
> MPRINT(COUNT_DATAFILES): select count(*) into :ant_arkiv from
> SAHA8800.arkiv;
> SYMBOLGEN: Macro variable BIBL resolves to SAHA8800
> MPRINT(COUNT_DATAFILES): select count(*) into :ant_sak from
> SAHA8800.sak;
> SYMBOLGEN: Macro variable BIBL resolves to SAHA8800
> MPRINT(COUNT_DATAFILES): select count(*) into :ant_dok from
> SAHA8800.dok;
> MPRINT(COUNT_DATAFILES): quit;
> NOTE: PROCEDURE SQL used:
> real time 0.42 seconds
> cpu time 0.08 seconds
>
>
> MLOGIC(COUNT_DATAFILES): Ending execution.
> MPRINT(TEST_DATAFILES): ;
> SYMBOLGEN: Macro variable BIBL resolves to SAHA8800
> WARNING: The Base Product product with which DATASTEP is associated
> will expire within 30 days.
> Please contact your SAS installation representative to have
> it renewed.
> MPRINT(TEST_DATAFILES): data SAHA8800.kompl_antall;
> SYMBOLGEN: Macro variable ANT_ARKIV resolves to 168
> MPRINT(TEST_DATAFILES): ARKIV = 168;
> SYMBOLGEN: Macro variable ANT_SAK resolves to 20385
> 22: LINE and COLUMN cannot be determined.
> NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow
> recovery of the LINE and COLUMN
> where the error has occurred.
> ERROR 22-322: Syntax error, expecting one of the following: a name, a
> quoted string,
> a numeric constant, a datetime constant, a missing
> value, INPUT, PUT.
> MPRINT(TEST_DATAFILES): SAK = 20385;
> WARNING: Apparent symbolic reference ANT_DOK not resolved.
> MPRINT(TEST_DATAFILES): DOK = &ant_dok;
> MPRINT(TEST_DATAFILES): run;
>
> NOTE: The SAS System stopped processing this step because of errors.
> WARNING: The data set SAHA8800.KOMPL_ANTALL may be incomplete. When
> this step was stopped there
> were 0 observations and 4 variables.
> WARNING: Data set SAHA8800.KOMPL_ANTALL was not replaced because this
> step was stopped.
> NOTE: DATA statement used:
> real time 0.00 seconds
> cpu time 0.00 seconds
>
>
> MLOGIC(TEST_DATAFILES): Ending execution.
>
> ---------------------------------------------
>
> What is wrong with my code ?
>
>
> Regards
> Rune Runnestoe
>