<?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 case when from the data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514412#M138729</link>
    <description>&lt;P&gt;Appreciate if someone of you help me to write the 'case when ...' statement to derive the variable 'KHIREF' from the following data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  WORK.INSURANCE_POLICY_0002(drop=POLICY_NO checkdigit x_source_system_cd);
  set  WORK.INSURANCE_POLICY_0002;
  format checkdigit z2.;
if POLICY_NO ^= '' then do;     
/* combine source code and policy number */
khiref=substr(left(x_source_system_cd),2,1)!!substr(left(policy_no),1,2)!!substr(left(policy_no),4,7);
/* calculate the checkdigit modulo 97. replace 0 by 97 */
checkdigit=compress(mod(khiref,97));
if checkdigit=0 then checkdigit=97;
/* add the checkdigit */
khiref=substr(left(khiref),1,10)!!vvalue(checkdigit);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sample data as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.INSURANCE_POLICY_0002;
/*length POLICY_NO $20.;*/
POLICY_NO='94_0006288';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Nov 2018 12:38:59 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2018-11-19T12:38:59Z</dc:date>
    <item>
      <title>case when from the data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514412#M138729</link>
      <description>&lt;P&gt;Appreciate if someone of you help me to write the 'case when ...' statement to derive the variable 'KHIREF' from the following data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  WORK.INSURANCE_POLICY_0002(drop=POLICY_NO checkdigit x_source_system_cd);
  set  WORK.INSURANCE_POLICY_0002;
  format checkdigit z2.;
if POLICY_NO ^= '' then do;     
/* combine source code and policy number */
khiref=substr(left(x_source_system_cd),2,1)!!substr(left(policy_no),1,2)!!substr(left(policy_no),4,7);
/* calculate the checkdigit modulo 97. replace 0 by 97 */
checkdigit=compress(mod(khiref,97));
if checkdigit=0 then checkdigit=97;
/* add the checkdigit */
khiref=substr(left(khiref),1,10)!!vvalue(checkdigit);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sample data as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.INSURANCE_POLICY_0002;
/*length POLICY_NO $20.;*/
POLICY_NO='94_0006288';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 12:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514412#M138729</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-19T12:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: case when from the data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514426#M138734</link>
      <description>&lt;P&gt;Your data step needs fixing:&lt;/P&gt;
&lt;PRE&gt;32         data  WORK.INSURANCE_POLICY_0002(drop=POLICY_NO checkdigit x_source_system_cd);
33           set  WORK.INSURANCE_POLICY_0002;
34           format checkdigit z2.;
35         if POLICY_NO ^= '' then do;
36         /* combine source code and policy number */
37         khiref=substr(left(x_source_system_cd),2,1)!!substr(left(policy_no),1,2)!!substr(left(policy_no),4,7);
38         /* calculate the checkdigit modulo 97. replace 0 by 97 */
39         checkdigit=compress(mod(khiref,97));
40         if checkdigit=0 then checkdigit=97;
41         /* add the checkdigit */
42         khiref=substr(left(khiref),1,10)!!vvalue(checkdigit);
43         end;
44         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      37:20   39:21   
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      39:12   39:25   
NOTE: Variable x_source_system_cd is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;Given the necessary intermediate steps, I'd recommend to stay with the data step, it's easier to read and maintain for such kind of logic.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514426#M138734</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-19T13:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: case when from the data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514434#M138735</link>
      <description>&lt;P&gt;See the blog post &lt;A href="https://blogs.sas.com/content/iml/2016/06/20/select-when-sas-data-step.html" target="_self"&gt;"The SELECT statement in the SAS DATA step."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514434#M138735</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-11-19T13:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: case when from the data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514500#M138742</link>
      <description>I have to implement this logic in DI studio and I was asked to use only&lt;BR /&gt;'case when'&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Nov 2018 17:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/case-when-from-the-data-step/m-p/514500#M138742</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-19T17:06:10Z</dc:date>
    </item>
  </channel>
</rss>

