BookmarkSubscribeRSS Feed
Obsidian | Level 7

Hello, Working on Visual Analytics 7.1 I have to join two tables table1 and table2 selecting only the observation with the MAX date_field in table2

So I open the data builder, create a new query, set up the join, select all the colums from both table that interest me and in the WHERE tab I write


table1.date_field = (
SELECT MAX(table1.date_field)
FROM library.table1

I save the query and try to validate it but an error appear. Checking the log I see that the SAS code generated is

31                 library.table1 table1
32             INNER JOIN
33                 library.table2 table2
34                     ON =
35             WHERE
36                 table1.date_field= (
37                     SELECT
38                                  table1.MAX (table1.date_field)
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

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


which is quite different from what I wrote. Maybe I'm missing something that I'm not seeing right now.

Thanks in advance.


PS: modifying by hand the generated sas code so that the subquery is written  correctly (basically removing the "table1." in front of MAX) the query works and the resulting table is generated without issue. Yet it isn't an optimal soluction



Opal | Level 21

I don't use VA, but SQL being SQL, it looks like you don't need a join at all


Proc sql;
create table table3 as
select * 
from table1
where date_field = (select max(date_field) from table2 where;

should be enough. 


Obsidian | Level 7
Yes, well I don't doubt there are better way to do this than through VA (also, my mistake the date field is in table1 only), my question was more about what was the deal with VA generating SAS code that way.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2 in conversation