<?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: question about making binary variables from an array in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496372#M15470</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show your expected output and it'll be clear (to me) what needs to change. Right now, you're creating a single variable that indicates first or second, but your data clearly indicates that both can occur. So what do you want to do when that case is encountered?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165633"&gt;@lmyers2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks so much for responding. What I'd like is for case 3 to be counted in both new_variable='first' and new_variable='second,' since the array contains both.&amp;nbsp; Is there a way to do this with the array syntax I have, maybe without the do loop?&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>Mon, 17 Sep 2018 19:09:22 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-09-17T19:09:22Z</dc:date>
    <item>
      <title>question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496348#M15466</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a simple question about making binary variables from an array.&amp;nbsp; Sample data and code are below. I believe my code will categorize Case 3 as 'first' and then it doesn't keep reading to SERVICE_EXTENDER2 to also include it as having a 'second.'&amp;nbsp; I tried using "else" in the code but that didn't help.&amp;nbsp; I'm sure there's an easy solution...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case&amp;nbsp; &amp;nbsp;SERVICE_EXTENDER1&amp;nbsp; &amp;nbsp;SERVICE_EXTENDER2&amp;nbsp; &amp;nbsp; SERVICE_EXTENDER3&amp;nbsp; &amp;nbsp; SERVICE_EXTENDER4&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;second&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; second&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have;
array SERVICE_EXTENDER [4] $ SERVICE_EXTENDER1-SERVICE_EXTENDER4;
do z=1 to 4;
if SERVICE_EXTENDER [z]='first' then new_variable='first';
if SERVICE_EXTENDER [z]='second' then new_variable='second'; 
end;
run;

proc freq data=want; tables new_variable*case_control / missing; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;laura&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496348#M15466</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2018-09-17T18:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496358#M15467</link>
      <description>&lt;P&gt;What are you trying to do here? It's not clear what you want as output.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496358#M15467</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T18:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496363#M15468</link>
      <description>&lt;P&gt;You likely only need WHICHC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;First_Flag = whichc('first', of service_extender1-service_extender4)&amp;gt;0;
Second_Flag = whichc('second', of service_extender1-service_extender4)&amp;gt;0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you do not need a loop or array declaration unless you really want to.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165633"&gt;@lmyers2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a simple question about making binary variables from an array.&amp;nbsp; Sample data and code are below. I believe my code will categorize Case 3 as 'first' and then it doesn't keep reading to SERVICE_EXTENDER2 to also include it as having a 'second.'&amp;nbsp; I tried using "else" in the code but that didn't help.&amp;nbsp; I'm sure there's an easy solution...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Case&amp;nbsp; &amp;nbsp;SERVICE_EXTENDER1&amp;nbsp; &amp;nbsp;SERVICE_EXTENDER2&amp;nbsp; &amp;nbsp; SERVICE_EXTENDER3&amp;nbsp; &amp;nbsp; SERVICE_EXTENDER4&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;second&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; second&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have;
array SERVICE_EXTENDER [4] $ SERVICE_EXTENDER1-SERVICE_EXTENDER4;
do z=1 to 4;
if SERVICE_EXTENDER [z]='first' then new_variable='first';
if SERVICE_EXTENDER [z]='second' then new_variable='second'; 
end;
run;

proc freq data=want; tables new_variable*case_control / missing; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;laura&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496363#M15468</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T18:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496370#M15469</link>
      <description>&lt;P&gt;Thanks so much for responding. What I'd like is for case 3 to be counted in both new_variable='first' and new_variable='second,' since the array contains both.&amp;nbsp; Is there a way to do this with the array syntax I have, maybe without the do loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496370#M15469</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2018-09-17T18:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496372#M15470</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show your expected output and it'll be clear (to me) what needs to change. Right now, you're creating a single variable that indicates first or second, but your data clearly indicates that both can occur. So what do you want to do when that case is encountered?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165633"&gt;@lmyers2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks so much for responding. What I'd like is for case 3 to be counted in both new_variable='first' and new_variable='second,' since the array contains both.&amp;nbsp; Is there a way to do this with the array syntax I have, maybe without the do loop?&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>Mon, 17 Sep 2018 19:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/496372#M15470</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T19:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: question about making binary variables from an array</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/497996#M15508</link>
      <description>You're right. I don't need the do loop. I just did a data step and searched within the array and it was much easier!</description>
      <pubDate>Fri, 21 Sep 2018 22:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/question-about-making-binary-variables-from-an-array/m-p/497996#M15508</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2018-09-21T22:21:50Z</dc:date>
    </item>
  </channel>
</rss>

