Help using Base SAS procedures

Macro error

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Macro error

Hi,

i have create this sas macro:

	%MACRO MACROFILTRO (TABELLA=, OWNER= );
	PROC SQL;
	CREATE TABLE ATM.T7_D_ELENCO_TERMINALI_IMP AS 

	SELECT * FROM ATM.T7_D_ELENCO_TERMINALI_IMP

	UNION ALL

	SELECT C.*, B.IM_TOT_CARIC, B.CO_ID_OLI
	FROM ATM.T7_D_ELENCO_TERMINALI_VER1 A
	INNER JOIN ATM.T01C_CANONI C ON (A.KEYATM = C.KEYATM)
	LEFT JOIN &OWNER..MOANAATM_&TABELLA B ON (A.KEYATM = B.KEYATM) /* 1° 102015 2° 082015 3° 062015 4* 042015 5° 022015 6° 012015 7°122014 8° 112014 9°062014 10° 012014 11° 082013*/
	WHERE B.KEYATM IS NOT NULL
	;
	quit;

	%MEND MACROFILTRO;
	%MACROFILTRO(TABELLA=%Str(102015), OWNER= %Str(TERM) );

why i have this error ?

1780      WHERE B.KEYATM IS NOT NULL
1781      ;
1782      quit;
1783
1784      %MEND MACROFILTRO;
1785      %MACROFILTRO(TABELLA=%Str(102015), OWNER= %Str(TERM) );
NOTE: Line generated by the macro variable "TABELLA".
1     TERM.MOANAATM_102015
                    ------
                    22
                     ------
                     200
ERROR 22-322: Syntax error, expecting one of the following: a name, (, AS, ON.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

Thanks!!!!!!!!!!!!!!!!!!!

 


Accepted Solutions
Solution
‎05-05-2016 08:58 AM
Respected Advisor
Posts: 4,766

Re: Macro error

SQL parses statements a little differently.  Try it this way:

 

%unquote(&OWNER..MOANAATM_&TABELLA)

 

View solution in original post


All Replies
Solution
‎05-05-2016 08:58 AM
Respected Advisor
Posts: 4,766

Re: Macro error

SQL parses statements a little differently.  Try it this way:

 

%unquote(&OWNER..MOANAATM_&TABELLA)

 

Contributor
Posts: 46

Re: Macro error

Perfect!!!!
thanks!!!
Esteemed Advisor
Esteemed Advisor
Posts: 6,989

Re: Macro error

Hi,

 

I know you have your answer but I wanted to throw a few things in there:

Firstly, why the macro in the first place, it doesn't seem to add anything.  Try not to obfuscate code for no reason.

- Try to avoid coding all in upper case, it makes reading code very hard.  I know SQL tends to put variables and tabes in uppercase, which is fine.  See below an example.

Finally, why are you union all data from the table and some other data?  Why not just insert the additional data into the existing dataset?  Again, example below:

proc sql;
  insert into ATM.T7_D_ELENCO_TERMINALI_IMP  
  select  C.*, 
          B.IM_TOT_CARIC, 
          B.CO_ID_OLI
  from    ATM.T7_D_ELENCO_TERMINALI_VER1 A
  inner join ATM.T01C_CANONI C 
  on      A.KEYATM=C.KEYATM
  left join TERM.MOANAATM_102015 B 
  on      A.KEYATM=B.KEYATM
  where   B.KEYATM IS NOT NULL;
quit;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 260 views
  • 1 like
  • 3 in conversation