SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
sun538
Obsidian | Level 7

Hi,

 

I ran the following code to do union a table with some manual values :

proc sql;
SELECT DISTINCT id, sub_id FROM mytable
union all select 'A','A'
union all select 'B','B'
union all select 'C','C' ;
quit;

 

However, I gets an error saying :

 

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, 
              AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, 
              LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  

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

 

Could you please let me know how I should change the code to perform well, as this same code is easily run in SQL Server. Thanks

2 REPLIES 2
ballardw
Super User

Create another data set that contains three rows of data and union that data set

 

Many (most) implementations of SQL have extensions that are not standard ANSI SQL. So just because some syntax works in one do not expect all of the "features" to work in another SQL. I suspect that the set operators Union and such are expected to work on Tables in the standard SQL and you have encountered yet another extension that SQL Server supports that other SQLs don't.

Tom
Super User Tom
Super User

You cannot just SELECT, you have to have something to select FROM.

Just make a little dataset.

data template;
  if 0 then set mytable(keep=id sub_id);
  input id sub_id;
cards;
A A
B B
C C
;

proc sql;
SELECT DISTINCT id, sub_id FROM mytable
union all select id, sub_id FROM template
;
quit;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1795 views
  • 4 likes
  • 3 in conversation