BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Gayle
Quartz | Level 8
I am gettting the error below but cannot figure out why.  Please look and advise the code is below.

ERROR: Teradata execute: Syntax error: expected something between the 'SELECT' keyword and the end of the request.

 


%put &=controlcellobs.; %macro cntlcellentrytest; %put &=controlcellobs.; %if &controlcellobs > 0 %then %do; %put "here in do"; proc sql; connect to teradata as eiwp (username=&a. password=&b. tdpid=&EIWP_TDPID. mode=teradata fastload=yes); select test, control into :test1 -, :control1 - from work.controlcell; %put _global_; %do i=1 %to sqlobs; execute(INSERT INTO work_05.CHD_TEST_X_CONTROL_test (cell_ky, comparison_ky, as_of_dt, insrt_dt_tm) SELECT &test.&i., &control.&i., as_of_dt, CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(0)) FROM (SELECT AS_OF_DT FROM CORE_V2.WAE_CALENDAR WHERE MO_AGO = 0) etl) by eiwp; quit; %end; %end; %else; %put 'No entries in control cells';

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Your macro variables need to be changed like this to resolve correctly to test1 and control1:

     &&test&i.
    ,&&control&i.

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

Rerun your program after adding - options mprint; - at the top. Then we can see the actual statements being executed. Not a SAS problem but a Teradata syntax problem. 

Tom
Super User Tom
Super User

Where is the rest of the definition of that macro?
Where is the code that actually called that macro?

  • Try aligning the indentation so it is a little easier to see what the code is doing. 
  • Try using a smaller tab size also so that the lines do not get so far shifted to the right that they are hard for humans to scan and align.
  • It also helps to indent the actual SAS code the macro is generating independently of the MACRO code that is used to generate it.
%macro cntlcellentrytest;
%put &=controlcellobs.;
%if &controlcellobs > 0 %then %do;
  %put "here in do";
proc sql;
connect to teradata as eiwp (username=&a. password=&b. tdpid=&EIWP_TDPID. mode=teradata fastload=yes);
select test
     , control 
  into :test1 -
     , :control1 -  
  from work.controlcell
;

  %do i=1 %to sqlobs;
execute
 (INSERT INTO work_05.CHD_TEST_X_CONTROL_test(cell_ky, comparison_ky, as_of_dt, insrt_dt_tm)
  SELECT
     &test.&i.
    ,&control.&i.
    ,as_of_dt
    ,CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(0))
  FROM
      (SELECT AS_OF_DT
        FROM CORE_V2.WAE_CALENDAR
        WHERE MO_AGO = 0
      ) etl
 )   
by eiwp;
quit;
  %end;
%end;
%else;
%put 'No entries in control cells';
/* What goes here? */
%mend cntlcellentrytest;

%let controlcellobs=what value should this have?
%put &=controlcellobs.;
%cntlcellentrytest;

Now it is much easier to see that the QUIT statement that ends the PROC SQL step is INSIDE the %DO loop.  So if SQLOBS is larger than 1 you will have problems with the SAS code you generated.

 

Also why is the last %PUT statement being run unconditionally?  Should that be inside of a %ELSE block? 

 

Do you really have a TERADATA schema named WORK_05?

 

Gayle
Quartz | Level 8

Thanks i changed the quit to be outside of the loop.  .  The %PUT at the else just informs of a an empty controlcell dataset.  I indicate below where the macro is invoked.  when i run this it is not resolving  the test and control macro variables. How do I get those to resolve?

error messages:

WARNING: Apparent symbolic reference TEST not resolved.
SYMBOLGEN:  Macro variable I resolves to 18
WARNING: Apparent symbolic reference CONTROL not resolved.
SYMBOLGEN:  Macro variable I resolves to 18
MPRINT(CNTLCELLENTRYTEST):   execute(INSERT INTO p_wae_u_work_05.CHD_TEST_X_CONTROL_test (cell_ky, comparison_ky, as_of_dt,
insrt_dt_tm) SELECT &test.18, &control.18, as_of_dt, CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(0)) FROM (SELECT AS_OF_DT FROM
CORE_V2.WAE_CALENDAR WHERE MO_AGO = 0) dtl) by eiwp;

 

 

code:

%macro cntlcellentrytest;
        %put &=controlcellobs.;
        %if &controlcellobs > 0 %then
                %do;
                        %put "here in do";
                 proc sql;
                  select test, control into :test1 -, :control1 -  from work.controlcell;
                 connect to teradata as eiwp (username=&a. password=&b. tdpid=&EIWP_TDPID. mode=teradata fastload=yes);
                        * select test, control into :test1 -, :control1 -  from work.controlcell;
                        %put _global_;
                        %do i=1 %to &controlcellobs;
                           execute(INSERT INTO p_wae_u_work_05.CHD_TEST_X_CONTROL_test
                           (cell_ky, comparison_ky, as_of_dt, insrt_dt_tm)
                           SELECT
                           &test.&i,
                           &control.&i,
                           as_of_dt,
                           CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(0))
                           FROM
                          (SELECT AS_OF_DT
                           FROM WAE_D_CORE_V2.WAE_CALENDAR
                           WHERE MO_AGO = 0) etl)   by eiwp;
                        %end;
                        quit;
                %end;
        %else;
                %put 'No entries in control cells';

%mend cntlcellentrytest;

%cntlcellentrytest;   ****here is where the macro is invoked
Tom
Super User Tom
Super User

Why are you still printing the no entries message even when there are entries?  Why did you indent the %PUT statement at a different level than the %ELSE and the %IF statement?  Just indenting the code does mean that it only runs when the %ELSE clause runs.  To do that you need to actually include it in the %ELSE clause.

 %else %put NOTE: No entries in control cells.;

Or use a %DO /%END block.

%else %do;
    %put NOTE: No entries in control cells.;
%end;
Gayle
Quartz | Level 8

Thank you ! I was wondering why this was printing despite entries.  

SASKiwi
PROC Star

Your macro variables need to be changed like this to resolve correctly to test1 and control1:

     &&test&i.
    ,&&control&i.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 4969 views
  • 1 like
  • 3 in conversation