<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replacing values in multiple columns using case statement in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615999#M180261</link>
    <description>&lt;P&gt;Thank you Kruger. That helped a lot . Am able to update the values in both the columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However one more doubt, is there any other alternate way to update the values in the columns when importing or reading the file using replace ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 17:59:58 GMT</pubDate>
    <dc:creator>Arvind1</dc:creator>
    <dc:date>2020-01-08T17:59:58Z</dc:date>
    <item>
      <title>Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615989#M180257</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table where in I have to replace value in two columns&amp;nbsp; ( Customer_Complaint and Status) based on the value present in them. I tried using SQL with CASE statement to modify the variables. However i am able to update values only in one particular column (Customer_Complaint) and not in other Status column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to update data in both columns ? I tried the below code, however i am getting an error when using multiple case statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table structure : Ticket /Customer_Complaint/ Status&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select * ,&lt;BR /&gt;case&lt;BR /&gt;when customer_complaint like '%Speed%' then 'Speed'&lt;BR /&gt;when customer_complaint like '%Service%' then 'Service'&lt;BR /&gt;when customer_complaint like '%Data%' then 'Data'&lt;BR /&gt;else 'Miscellaneous'&lt;BR /&gt;end as Customer_Complaint1&lt;/P&gt;&lt;P&gt;Case&amp;nbsp;&lt;/P&gt;&lt;P&gt;when status like 'Pending' then 'Closed'&lt;/P&gt;&lt;P&gt;end as Status_1&lt;BR /&gt;from work.comcast;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way that i first update the data in the first column (Customer_Complaint), write into a temporary file and then perform operation on the temporary file to update the Status column?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or is there a way to update file using replace? Please guide&lt;/P&gt;&lt;P&gt;thanks in advance for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615989#M180257</guid>
      <dc:creator>Arvind1</dc:creator>
      <dc:date>2020-01-08T17:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615990#M180258</link>
      <description>&lt;P&gt;You are missing a comma after Customer_Complaint1 which I added in. This would cause only 1 row to appear assuming it would run successfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also want to add an ELSE to your CASE for Status_1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * ,
case
when customer_complaint like '%Speed%' then 'Speed'
when customer_complaint like '%Service%' then 'Service'
when customer_complaint like '%Data%' then 'Data'
else 'Miscellaneous'
end as Customer_Complaint1,

Case 

when status like 'Pending' then 'Closed'

end as Status_1
from work.comcast;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615990#M180258</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2020-01-08T17:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615991#M180259</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/306127"&gt;@Arvind1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table where in I have to replace value in two columns&amp;nbsp; ( Customer_Complaint and Status) based on the value present in them. I tried using SQL with CASE statement to modify the variables. However i am able to update values only in one particular column (Customer_Complaint) and not in other Status column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to update data in both columns ? I tried the below code, however i am getting an error when using multiple case statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us the log (the code in the log as well as the error messages in the log)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615991#M180259</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-08T17:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615999#M180261</link>
      <description>&lt;P&gt;Thank you Kruger. That helped a lot . Am able to update the values in both the columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However one more doubt, is there any other alternate way to update the values in the columns when importing or reading the file using replace ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/615999#M180261</guid>
      <dc:creator>Arvind1</dc:creator>
      <dc:date>2020-01-08T17:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616000#M180262</link>
      <description>&lt;P&gt;Thanks Paige . The solution has been arrived. However would like to know if there is an alternate way of replacing the data in the file other than the sql method.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 18:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616000#M180262</guid>
      <dc:creator>Arvind1</dc:creator>
      <dc:date>2020-01-08T18:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616008#M180267</link>
      <description>&lt;P&gt;How are you reading the data.&amp;nbsp; I should be simple to write DATA STEP code to do what ever you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using a data step to create the original file then just add the logic to that step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data comcast;
  ... whatever logic you currently have that creates CUSTOMER_COMPLAINT and STATUS ...
  Customer_Complaint1= 'Miscellaneous';
  select ;
    when (index(customer_complaint,'Speed')) Customer_Complaint1='Speed';
    when (index(customer_complaint,'Service')) Customer_Complaint1='Service';
    when (index(customer_complaint,'Data')) Customer_Complaint1='Data';
    otherwise ;
  end;
  if status='Pending' then Status_1='Closed';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jan 2020 18:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616008#M180267</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-08T18:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616013#M180269</link>
      <description>I'd recommend a data step and listing the words in a temporary array and then looping through the temporary array. That way if your word list gets longer you're only updating the list once.&lt;BR /&gt;&lt;BR /&gt;What happens if a statement has more than one of the keywords?</description>
      <pubDate>Wed, 08 Jan 2020 18:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616013#M180269</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-08T18:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616099#M180310</link>
      <description>&lt;P&gt;Thanks everyone for your responses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To give a background, i am doing a data clean up of the columns - Customer complaint and Status. When there is a word speed in the customer complaint i would want to mark it as speed issues and when there is poor customer service i would want to mark it as service issue etc.&amp;nbsp; rest of the complaints would be miscellaneous.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other than the SQL method is there anyother way that i can replace the data in the file. Attaching the file for your reference and the working SQL query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FILENAME REFFILE "/home/u44638328/Comcast.csv";&lt;/P&gt;&lt;P&gt;proc import datafile=REFFILE&lt;BR /&gt;DBMS=CSV&lt;BR /&gt;OUT=work.Comcast replace;&lt;BR /&gt;getnames=YES;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select * ,&lt;BR /&gt;case&lt;BR /&gt;when customer_complaint like '%Speed%' then 'Speed'&lt;BR /&gt;when customer_complaint like '%speed%' then 'Speed'&lt;BR /&gt;when customer_complaint like '%Service%' then 'Service'&lt;BR /&gt;when customer_complaint like '%service%' then 'Service'&lt;BR /&gt;when customer_complaint like '%Data%' then 'Data'&lt;BR /&gt;when customer_complaint like '%data%' then 'Data'&lt;BR /&gt;when customer_complaint like '%billing%' then 'Billing'&lt;BR /&gt;when customer_complaint like '%Billing%' then 'Billing'&lt;BR /&gt;when customer_complaint like '%Price%' then 'Pric'&lt;BR /&gt;when customer_complaint like '%Outage%' then 'Outage'&lt;BR /&gt;when customer_complaint like '%outage%' then 'Outage'&lt;BR /&gt;else 'Miscellaneous'&lt;BR /&gt;end as Customer_Complaint1,&lt;/P&gt;&lt;P&gt;Case&lt;BR /&gt;when status like '%end%' then 'Open'&lt;BR /&gt;when status like '%ved%' then 'Closed'&lt;BR /&gt;when status like 'Closed' then 'Closed'&lt;BR /&gt;when status like 'Open' then 'Open'&lt;/P&gt;&lt;P&gt;end as Status_1&lt;BR /&gt;from work.comcast;&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 02:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616099#M180310</guid>
      <dc:creator>Arvind1</dc:creator>
      <dc:date>2020-01-09T02:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing values in multiple columns using case statement in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616229#M180382</link>
      <description>&lt;P&gt;I'm new to SAS so unsure if this is going to run as expected but here's doing it as a datastep. You can use upcase() or lowcase() to remove some of your duplicate code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set work.comcast;
	if upcase(customer_complaint) = 'SERVICE' then Customer_Complaint1='Service';
	else if upcase(customer_complaint) = 'DATA' then Customer_Complaint1='Data';
	else if upcase(customer_complaint) = 'BILLING' then Customer_Complaint1='Billing';
	else if upcase(customer_complaint) = 'PRICE' then Customer_Complaint1='Price';
	else if upcase(customer_complaint) = 'OUTAGE' then Customer_Complaint1='Outage';
	else Customer_Complaint1='Miscellaneous';

	if upcase(status) = 'END' then Status_1 = 'Open';
	else if upcase(status) = 'VED' then Status_1 = 'Closed';
	else if upcase(status) = 'CLOSED' then Status_1 = 'Closed';
	else if upcase(status) = 'OPEN' then Status_1 = 'Open';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some example data would also be helpful. I'm assuming the above isn't going to fully work as it appears your searching a string of text. In that case you will likely need to experiment with the find() function in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Instead of find() you might have to do =: in place of like.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 15:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-values-in-multiple-columns-using-case-statement-in-SQL/m-p/616229#M180382</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2020-01-09T15:26:21Z</dc:date>
    </item>
  </channel>
</rss>

