BookmarkSubscribeRSS Feed
Sandeep77
Lapis Lazuli | Level 10

Hi Experts,

I am trying to find the distinct phone numbers but getting sytax error. Could you check and let me know what is causing this error?

Thank you 

proc sql;
create table Tele_numbers as 
select a.*,
distinct b.tnphone as telephone,
case when
b.tnphone is not null then 'Y' else 'N'
end as Number_available
from Repcodes as a
Inner join
p2scflow.telephonenumbers as b on a.Accounts_number = b.tnkey;
quit;

Error:


29         proc sql;
30         create table Tele_numbers as
31         select a.*,
32         
33         distinct b.tnphone as telephone,
                    _
                    22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

34         case when
35         b.tnphone is not null then 'Y' else 'N'
36         end as Number_available
37         from Repcodes as a
38         Inner join
39         p2scflow.telephonenumbers as b on a.Accounts_number = b.tnkey;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
40         quit;
2 REPLIES 2
Tom
Super User Tom
Super User

The DISTINCT keyword applies to the entire observation.  Place it before the variable list, not in the middle.

LinusH
Tourmaline | Level 20

Also, adding a.* would probably give a lot more records than you desire, if you want a neat least of unique phone numbers.

Data never sleeps

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 705 views
  • 2 likes
  • 3 in conversation