BookmarkSubscribeRSS Feed
manjuhiten28
Calcite | Level 5

I have a datset of Comcast Telecom Consumer Complaints .I need help . To create a new variable in my existing dataset in new column.

. i am poviding a screenshot  of my dataset   in photos

Data Dictionary

  • Ticket #: Ticket number assigned to each complaint
  • Customer Complaint: Description of complaint
  • Date: Date of complaint
  • Time: Time of complaint
  • Received Via: Mode of communication of the complaint
  • City: Customer city
  • State: Customer state
  • Zipcode: Customer zip
  • Status: Status of complaint
  • Filing on behalf of someone
  • Analysis Task

Create a new categorical variable with value as Open and Closed. Open & Pending is to be categorized as Open and Closed & Solved is to be categorized as Closed

i tried many ways but  unable to create new variable

1)
data mylib.concast4;
set mylib.concast;
if Status in('Open','Pending') then new_status='Open';
else Status in('Closed ','Solved' ) then new_status='Closed';
run;
error is 
 error: statement is not valid or out of  proper order.
2)
proc sql;
create table mylib.concast4 as
select * from  mylib.concast
case
when status in ('open' ,'pending') then new_status='open'
when status in ('closed','solved') then new_status='closed'
else 'others'
end as new_status
from  mylib.concast;
quit;

error is ;
ERROR 22-322: Syntax error, expecting one of the following: ;, ',', ANSIMISS, CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT, 
               JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER, RIGHT, UNION, WHERE.  
 
 ERROR 76-322: Syntax error, statement will be ignored
 
 

sample datset.PNG

 please help me.

3 REPLIES 3
andreas_lds
Jade | Level 19

Please post the complete log as text.

Kurt_Bremser
Super User

0) DO NOT post data in pictures, use a data step with datalines so we can easily recreate your dataset.

 

1) a "then" always needs an "if":

data mylib.concast4;
set mylib.concast;
if Status in('Open','Pending') then new_status='Open';
else if Status in('Closed ','Solved' ) then new_status='Closed';
run;

2) why do you have two "from" clauses in your SQL select? Only one is needed, and it has to come AFTER the column list:

proc sql;
create table mylib.concast4 as
select
  *, 
  case
    when status in ('open' ,'pending') then new_status='open'
    when status in ('closed','solved') then new_status='closed'
    else 'others'
  end as new_status
from  mylib.concast;
quit;

Make sure that your literals match the contents of status in terms of spelling and capitalization.

Gupta
Calcite | Level 5
Can you please share complete solution for this to me, Thank you for your kind help in advance.

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!
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
  • 3 replies
  • 1092 views
  • 0 likes
  • 4 in conversation