BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

Hi Experts,

I have created a table with phone numbers. Now I am trying to divide the phone numbers into mobile and landline numbers. Suppose if the mobile number starts with 07 then I am using the below code but getting some error in the code. Can you please suggest?

proc sql;
create table Mobile_numbers as
select a.*,
case when dr_phone like (07%)  then 'Mobile' else 'Landline'
end as Mobile_or_Landline
from Telephone_numbers;
quit;

Error:
29         proc sql;
30         create table Mobile_numbers as
31         select a.*,
32         case when dr_phone like (07%)  then 'Mobile' else 'Landline'
                                      _
                                      22
                                      200
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.  

ERROR 200-322: The symbol is not recognized and will be ignored.

33         end as Mobile_or_Landline
34         from Telephone_numbers;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
35         quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you want to refer to the dataset Telephone_numbers with the alias A then you need to tell SQL that in the FROM clause.

create table Mobile_numbers as
  select a.*
       , case when dr_phone like '07%' then 'Mobile' else 'Landline'
         end as Mobile_or_Landline
  from Telephone_numbers a
;

Or just remove the a. from before the * in the list of variables.

View solution in original post

5 REPLIES 5
ballardw
Super User

Is your phone number actually a number or character? If character the syntax would be '07%' to indicate the comparison value.

If numeric "like" is not going to appropriate at all.

Sandeep77
Lapis Lazuli | Level 10

It's a character value. So I made the changes to '07%' but it still shows the below error. 

proc sql;
create table Mobile_numbers as
select a.*,
case when dr_phone like '07%' then 'Mobile' else 'Landline'
end as Mobile_or_Landline
from Telephone_numbers;
quit;

error:
29         proc sql;
30         create table Mobile_numbers as
31         select a.*,
32         case when dr_phone like '07%' then 'Mobile' else 'Landline'
33         end as Mobile_or_Landline
34         from Telephone_numbers;
ERROR: Could not expand a.*, correlation name not found.
ERROR: The following columns were not found in the contributing tables: a.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
35         quit;
Tom
Super User Tom
Super User

If you want to refer to the dataset Telephone_numbers with the alias A then you need to tell SQL that in the FROM clause.

create table Mobile_numbers as
  select a.*
       , case when dr_phone like '07%' then 'Mobile' else 'Landline'
         end as Mobile_or_Landline
  from Telephone_numbers a
;

Or just remove the a. from before the * in the list of variables.

Sandeep77
Lapis Lazuli | Level 10

Thank you. Got it!

yaakov555
Fluorite | Level 6
case when dr_phone like '(07%)' then 'Mobile' else 'Landline'

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 724 views
  • 3 likes
  • 4 in conversation