<?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: Proc sql case when condition to create multiple variables vs data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427431#M105407</link>
    <description>&lt;P&gt;You could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table names as
select
    full_name,
    case when countw(full_name) = 1 then substr(full_name,1,8) else scan(full_name,1) end as first_name,
    case when countw(full_name) = 1 then substr(full_name,9,9) else scan(full_name,2) end as last_name
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 13 Jan 2018 07:23:04 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-01-13T07:23:04Z</dc:date>
    <item>
      <title>Proc sql case when condition to create multiple variables vs data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427422#M105399</link>
      <description>&lt;P&gt;Sas Gurus,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying to create this data step in proc sql with case when statement and I am getting syntax errors. Any idea how to solve this? Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA NAMES;&lt;BR /&gt;INPUT full_name $20.;&lt;BR /&gt;if index(full_name, ' ') = 0 then do;&lt;BR /&gt;first_name = substr(full_name,1,8);&lt;BR /&gt;last_name = substr(full_name,9,9);&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;first_name = scan(full_name,1,' ');&lt;BR /&gt;last_name = substr(full_name, index(full_name,' '));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 05:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427422#M105399</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-01-13T05:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql case when condition to create multiple variables vs data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427431#M105407</link>
      <description>&lt;P&gt;You could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table names as
select
    full_name,
    case when countw(full_name) = 1 then substr(full_name,1,8) else scan(full_name,1) end as first_name,
    case when countw(full_name) = 1 then substr(full_name,9,9) else scan(full_name,2) end as last_name
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Jan 2018 07:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427431#M105407</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-13T07:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql case when condition to create multiple variables vs data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427453#M105420</link>
      <description>&lt;P&gt;Thank you for the suggestion Pgstat. I do have last name that have gaps in last names and that is different when I compare both with proc compare. Is there a way to fix this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 17:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427453#M105420</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2018-01-13T17:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql case when condition to create multiple variables vs data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427471#M105433</link>
      <description>&lt;P&gt;Give an example, please.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 21:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-case-when-condition-to-create-multiple-variables-vs/m-p/427471#M105433</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-13T21:47:30Z</dc:date>
    </item>
  </channel>
</rss>

