<?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: Creating a single variable from multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532742#M6077</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255712"&gt;@aowais&lt;/a&gt;&amp;nbsp; here is a demo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
array t(*) co7_1-co7_8 (7*0 1);
run;

data two;
set one;
array t(*) co7_1--co7_8;
public_care= max(of t(*))=1  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TWO" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;co7_1&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_2&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_3&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_4&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_5&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_6&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_7&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_8&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;public_care&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 04 Feb 2019 20:56:10 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-04T20:56:10Z</dc:date>
    <item>
      <title>Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532735#M6071</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a binary variable based on the responses in 8 other variables. I'm currently using the following code, which is working, but I was wondering if there is a better way to do this, such as using arrays?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two; set one;&lt;BR /&gt;if co7_1 = 1 or co7_2 = 1 or co7_3 = 1 or co7_4 = 1 or co7_5 = 1 or&lt;BR /&gt;co7_6 = 1 or co7_7 = 1 or co7_8= 1 then public_care = 1;&lt;BR /&gt;else public_care = 0;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532735#M6071</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-02-04T20:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532736#M6072</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two; set one;
/*if co7_1 = 1 or co7_2 = 1 or co7_3 = 1 or co7_4 = 1 or co7_5 = 1 or*/
/*co7_6 = 1 or co7_7 = 1 or co7_8= 1 then public_care = 1;*/
/*else public_care = 0;*/

array t(*) co7_1--co7_8;
public_care= max(of t(*))=1  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532736#M6072</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T20:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532739#M6074</link>
      <description>Do you really need an array here?</description>
      <pubDate>Mon, 04 Feb 2019 20:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532739#M6074</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-04T20:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532740#M6075</link>
      <description>&lt;P&gt;No&amp;nbsp; but&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; demonstrated many times to avoid var: lists as that could lead to some ambiguity which made sense and henceforth I am in agreement to that best practice&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me see if I can find that thread&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532740#M6075</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T20:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532741#M6076</link>
      <description>Thanks, but this results in all values for public_care = 0...</description>
      <pubDate>Mon, 04 Feb 2019 20:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532741#M6076</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-02-04T20:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532742#M6077</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255712"&gt;@aowais&lt;/a&gt;&amp;nbsp; here is a demo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
array t(*) co7_1-co7_8 (7*0 1);
run;

data two;
set one;
array t(*) co7_1--co7_8;
public_care= max(of t(*))=1  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TWO" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;co7_1&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_2&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_3&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_4&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_5&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_6&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_7&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;co7_8&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;public_care&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532742#M6077</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T20:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532753#M6080</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255712"&gt;@aowais&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks, but this results in all values for public_care = 0...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show the exact code you ran from the log. It is very easy to make a typo that may do that but without your code we can't tell where.&lt;/P&gt;
&lt;P&gt;And some example input values for the variables that generate 0.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532753#M6080</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-04T21:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532755#M6082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Do you really need an array here?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;was referring to the fact that you can use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;public_care= max(of co7_1-co7_8)=1  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and no arrays are needed.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532755#M6082</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-04T21:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532757#M6084</link>
      <description>&lt;P&gt;ah ok&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532757#M6084</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T21:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532763#M6085</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;I understand your comment, but if the array declaration is the same as in the OF there's no need for the array declaration. Unless you're using it more than once, then I'll create it because I'm a lazy typist.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532763#M6085</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-04T21:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532767#M6086</link>
      <description>&lt;P&gt;got it. thick brains didn't get that insight at first until quantmiller clarified. I am even more convinced our search algorithm is paigerank algorithm. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532767#M6086</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T21:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532786#M6088</link>
      <description>&lt;P&gt;Without knowing the range of values these variables take on, there is no way to know whether the codes are equivalent.&amp;nbsp; It's possible that the max value for some of the variables is 3 instead of 1.&amp;nbsp; That generates a very different outcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could probably switch to this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;public_care = (whichn(1, of col7_1-col7_8) &amp;gt; 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, but looks about right.&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>Mon, 04 Feb 2019 22:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532786#M6088</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-04T22:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a single variable from multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532817#M6092</link>
      <description>&lt;P&gt;This worked! Thank you! You were right about the values being the issue. The values included 1, 2, 555 and some missing.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 00:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-single-variable-from-multiple-variables/m-p/532817#M6092</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-02-05T00:14:14Z</dc:date>
    </item>
  </channel>
</rss>

