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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 352 views
  • 2 likes
  • 3 in conversation