Home > Enterprise >  Syntax error when creating a table in sas
Syntax error when creating a table in sas

Time:12-22

I am learning to program in sas and sql and I would like to create a table that contains the value of yesterday (I have stored it in the macrovariable & yesterday), the difference in the amount between the days and the amount of yesterday and the day before yesterday .

Supposedly the code should be fine, the spaces are put by post in the macrovariables, in fact the error that it returns is syntax, it does not tell me that it does not find such a date or anything like that.

This is my code:

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_TRANSPOSED_DAYBEFORE AS 
         SELECT &yesterday. AS dia_ayer, 
          abs((t1."    &yesterday."n - t1."    &before_yesterday."n) / t1."    &before_yesterday."n) end AS Diferencia_dias, 
          t1."    &before_yesterday."n, 
          t1."    &yesterday."n
      FROM WORK.Transposed_daybefore t1;
QUIT;

I get this syntax error right after & before_yesterday. "N) end as Difference_days, just after) and before "end"

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **,  , ',', -, /, <, <=, <>, =, >, >=, ?, AND, AS, 
              CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=. 

and it returns this error just before the FROM:

ERROR 22-322: Syntax error, expecting one of the following: un nombre, ;, (, ',', ANSIMISS, AS, CROSS, EXCEPT, FULL, GROUP, HAVING, 
              INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER, RIGHT, UNION, WHERE.  

ERROR 76-322: Syntax error, statement will be ignored.

I would be very grateful if you help me find the error, thank you very much in advance.

CodePudding user response:

I tried to replicate your code, even though I did not quite get what you're trying to achieve.

First of all, lets try removing end at the select clause. Second of all, you're trying to access the macrovariable within the table, via t1. &yesterday, which also seems wrong.

Try this code below:

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_TRANSPOSED_DAYBEFORE AS 
         SELECT &yesterday. AS dia_ayer, 
          abs((&yesterday - &before_yesterday) / &before_yesterday) AS Diferencia_dias, 
          &before_yesterday, 
          &yesterday
      FROM WORK.Transposed_daybefore t1;
QUIT;
  • Related