<?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: datatype issue in case step output of proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876627#M346320</link>
    <description>&lt;P&gt;There is a small issue in your query. You have mentioned&amp;nbsp;specifier= after "then" in 3rd CASE-WHEN statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the corrected query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
infile datalines missover;
input id specifier $  ;
datalines;
01 class1 
02 123    
03 3456   
04 aaaa   
05 N/A 
06 
;
run;

proc sql;
create table two as select id,
case 
     when specifier is missing then "unspecified"
     when specifier="aaaa" or specifier="N/A" then "12345"
     when length(specifier)=3 then cats(0,specifier)
     else specifier
     end as specifier_new
from one;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 May 2023 09:43:52 GMT</pubDate>
    <dc:creator>MayurJadhav</dc:creator>
    <dc:date>2023-05-19T09:43:52Z</dc:date>
    <item>
      <title>datatype issue in case step output of proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876626#M346319</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am getting below error when I try to run attached code. There is some issue with data type.How can it be rectified in the case step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Result of WHEN clause 3 is not the same data type as the preceding results.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data one;
infile datalines missover;
input id specifier $  ;
datalines;
01 class1 
02 123    
03 3456   
04 aaaa   
05 N/A 
06 
;
run;

proc sql;
create table two as select id,
case 
     when specifier is missing then "unspecified"
     when specifier="aaaa" or specifier="N/A" then "12345"
     when length(specifier)=3 then specifier=cats(0,specifier)
     else specifier
     end as specifier_new
from one;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 09:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876626#M346319</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-19T09:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: datatype issue in case step output of proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876627#M346320</link>
      <description>&lt;P&gt;There is a small issue in your query. You have mentioned&amp;nbsp;specifier= after "then" in 3rd CASE-WHEN statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the corrected query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
infile datalines missover;
input id specifier $  ;
datalines;
01 class1 
02 123    
03 3456   
04 aaaa   
05 N/A 
06 
;
run;

proc sql;
create table two as select id,
case 
     when specifier is missing then "unspecified"
     when specifier="aaaa" or specifier="N/A" then "12345"
     when length(specifier)=3 then cats(0,specifier)
     else specifier
     end as specifier_new
from one;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 May 2023 09:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876627#M346320</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-05-19T09:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: datatype issue in case step output of proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876628#M346321</link>
      <description>&lt;P&gt;From now on, please when there are problems in the log, show use the ENTIRE log for this PROC. Do not show us partial logs!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHEN clause 3 is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     when length(specifier)=3 then specifier=cats(0,specifier)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the value of the part&lt;FONT face="courier new,courier"&gt; specifier=cats(0,specifier)&lt;/FONT&gt;??? This is a Boolean comparison, does the variable on the left equal the value of the function on the right? So the value of this Boolean comparison is numeric and has values either 0 or 1 or missing. A numeric cannot be assigned by this WHEN clause and a character string is assigned by other WHEN clauses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     when length(specifier)=3 then cats(0,specifier)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;because cats(0,specifier) is a character string, that works with other WHEN clauses also assign character strings.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 11:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datatype-issue-in-case-step-output-of-proc-sql/m-p/876628#M346321</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-19T11:17:45Z</dc:date>
    </item>
  </channel>
</rss>

