<?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 for multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762174#M241274</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to create another column based on this objective - as long as the client visit any day from Day1 to Day3, they will be tagged in another column called Visit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking of using case when in proc sql but I am stuck with the syntax or if case when is even the proper statement to use. Basically, the output will be:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3 Visit&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
    <pubDate>Tue, 17 Aug 2021 21:38:21 GMT</pubDate>
    <dc:creator>rapt1</dc:creator>
    <dc:date>2021-08-17T21:38:21Z</dc:date>
    <item>
      <title>Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762174#M241274</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to create another column based on this objective - as long as the client visit any day from Day1 to Day3, they will be tagged in another column called Visit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking of using case when in proc sql but I am stuck with the syntax or if case when is even the proper statement to use. Basically, the output will be:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3 Visit&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 21:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762174#M241274</guid>
      <dc:creator>rapt1</dc:creator>
      <dc:date>2021-08-17T21:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762182#M241280</link>
      <description>&lt;P&gt;Using math makes the problem simple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when sum(day1,day2,day3) &amp;gt; 0 then 1 else 0 end as visit&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Aug 2021 21:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762182#M241280</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-17T21:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762183#M241281</link>
      <description>&lt;P&gt;Thanks! Is this also a valid syntax when a row/observation contains a missing value? Say,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;JKL&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;&lt;BR /&gt;I think I got this error:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: Invalid (or missing) arguments to the XXX function have caused the function to return a missing value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 22:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762183#M241281</guid>
      <dc:creator>rapt1</dc:creator>
      <dc:date>2021-08-17T22:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762187#M241283</link>
      <description>&lt;P&gt;I'm not getting this particular note when I use missing values. (and you didn't get an ERROR, you got a NOTE)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us the ENTIRE log from this code (so we can see the code and the ERRORs, WARNINGs and NOTEs). Do not pick parts to show us and then not show us other parts of the log. Please copy the entire log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. &lt;STRONG&gt;DO NOT SKIP THIS STEP&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 22:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762187#M241283</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-17T22:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762191#M241286</link>
      <description>&lt;P&gt;You're doing something differently than suggested then. Why did you blank out the XXX? What does that mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This generates no errors or warnings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 80         
 81         
 82         proc sql;
 83         create table want as
 84         select *, case when sum(day1, day2, day3) &amp;gt; 0 then 1 else 0 end as visit
 85         from have;
 NOTE: Table WORK.WANT created, with 4 rows and 5 columns.
 
 86         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              5465.87k
       OS Memory           29096.00k
       Timestamp           08/17/2021 10:21:06 PM
       Step Count                        32  Switch Count  2
       Page Faults                       0
       Page Reclaims                     205
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/379057"&gt;@rapt1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks! Is this also a valid syntax when a row/observation contains a missing value? Say,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Client Day1 Day2 Day3&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;GHI&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;JKL&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;&lt;BR /&gt;I think I got this error:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: Invalid (or missing) arguments to the XXX function have caused the function to return a missing value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 22:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762191#M241286</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-17T22:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762192#M241287</link>
      <description>You will get that NOTE if you have ALL missing values though. &lt;BR /&gt;How do you want to handle that case - explicitly deal with it.&lt;BR /&gt;This codes it to -1.&lt;BR /&gt;&lt;BR /&gt;case when nmiss(day1, day2, day3) eq 3 then -1&lt;BR /&gt;          when sum(day1, day2, day3) &amp;gt; 0 then 1 &lt;BR /&gt;          else 0 end as visit</description>
      <pubDate>Tue, 17 Aug 2021 22:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762192#M241287</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-17T22:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762194#M241289</link>
      <description>&lt;P&gt;To handle all missing values, another way is:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;when sum(day1, day2, day3, 0) &amp;gt; 0 then 1&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 22:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762194#M241289</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-17T22:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762242#M241317</link>
      <description>&lt;P&gt;Sometimes using a data step instead of proc sql avoids unnecessary notes and keeps code short.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   Visit = sum(of Day:) &amp;gt; 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 09:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762242#M241317</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-18T09:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762244#M241318</link>
      <description>&lt;P&gt;The logical shortcut can also be used in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    t1.*,
    (sum(day1,day2,day3,0) &amp;gt; 0) as visit
  from have t1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 09:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762244#M241318</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-18T09:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Case when for multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762249#M241321</link>
      <description>&lt;P&gt;Thank you everyone for the inputs! I would try to do all your suggestions and look into data step as well. I have been using proc sql since I am more familiar with sql but will get into data step soon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, thank you for the reminder on sharing the code. I oftentimes forget about this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 12:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-for-multiple-columns/m-p/762249#M241321</guid>
      <dc:creator>rapt1</dc:creator>
      <dc:date>2021-08-18T12:12:00Z</dc:date>
    </item>
  </channel>
</rss>

