<?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 new variable based on a string of similar variables with identical responses in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723667#M224600</link>
    <description>&lt;P&gt;The code you posted treats your data as numeric not character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use WHICHC() instead of WHICHN() then.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documentations on functions are available here&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want ti book mark the formats and informats by category page (find them from the main documentation.sas.com page).&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 21:37:48 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-04T21:37:48Z</dc:date>
    <item>
      <title>Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723640#M224582</link>
      <description>&lt;P&gt;I have five survey variables, similar in naming convention:&amp;nbsp; ABC1, ABC2, ABC3, ABC4, and ABC5.&amp;nbsp; Responses for these variables are either 1 or 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to shorten/simplify my code of:&lt;/P&gt;&lt;P&gt;If ABC1=1 and ABC2=1 and ABC3=1 and ABC4=1 and ABC5 =1 then CODE=8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I simplify that code?&amp;nbsp; In my real scenario, my last variable is ABC100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 20:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723640#M224582</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2021-03-04T20:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723649#M224585</link>
      <description>It depends a bit on the full logic. An alternative equivalent calculation would be that the SUM() of all those items would be 100. &lt;BR /&gt;&lt;BR /&gt;/*all values are 1 - assumes no missing values*/&lt;BR /&gt;if sum(of abc1-abc100) = 100 then code=8;&lt;BR /&gt;&lt;BR /&gt;/*checks if any value of 2 is in the list of variables*/&lt;BR /&gt;IF WHICHN('2', of ABC1-ABC100) =0 then code=8</description>
      <pubDate>Thu, 04 Mar 2021 21:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723649#M224585</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T21:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723651#M224587</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;If ABC1=1 and ABC2=1 and ABC3=1 and ABC4=1 and ABC5 =1 then CODE=8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I simplify that code?&amp;nbsp; In my real scenario, my last variable is ABC100.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if nmiss(of abc:)=0 and min(of abc:)=1 and max(of abc:)=1;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723651#M224587</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-04T21:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723653#M224589</link>
      <description>&lt;P&gt;Sorry,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;, I just stop by and feel interesting in the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please tell me how to search the documents to learn about&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sum(of...) or nmiss(of...)&lt;/STRONG&gt;, or is there any document in your head that you think can help me to learn about these nice functions (with &lt;STRONG&gt;of&lt;/STRONG&gt; inside bracket)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723653#M224589</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-04T21:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723655#M224591</link>
      <description>&lt;P&gt;If your variables are numeric you can test the RANGE of values. If the Range is 0 all of the values are the same.&lt;/P&gt;
&lt;P&gt;So you test the range and a single (non-missing) variable for its value. If it is 1 then all the values are 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if range (of ABC: )=0 and Abc1=1 then code=8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ABC: uses all the variables whose names start with ABC. Or use range(of Abc1-Abc100) to use sequentially numbered variables. If there is a gap in the numbers, maybe you don't want to use ABC49 for some particular reason, you can provide two (or more) similar lists:&amp;nbsp; range(of abc1-abc48, of abc50-abc100);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Range will ignore missing values in the calculation. So if the requirement is to have no missing value you could add:&lt;/P&gt;
&lt;P&gt;and nmiss(of abc:)=0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also consider coding things as 1/0 instead and treat 1 as the condition most often of interest (Yes) perhaps.&lt;/P&gt;
&lt;P&gt;Then an "all 100 variables must be exactly 1" becomes: &amp;nbsp; sum(of abc1-abc100)=100&lt;/P&gt;
&lt;P&gt;If you want to know that at least one variables has the value 1 (in this 1/0) coding scheme: max(of abc1-abc100)=1&lt;/P&gt;
&lt;P&gt;At least one of the variables has a 0&amp;nbsp; : min (of abc1-abc100)=0.&lt;/P&gt;
&lt;P&gt;Percent of variables with responses that answered 1 : mean(of abc1-abc100)&amp;nbsp; yields the decimal percentage such as .125 =12.5%&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723655#M224591</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T21:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723657#M224593</link>
      <description>My variables ABC1 through ABC100 are defined as character so I get an error.</description>
      <pubDate>Thu, 04 Mar 2021 21:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723657#M224593</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2021-03-04T21:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723667#M224600</link>
      <description>&lt;P&gt;The code you posted treats your data as numeric not character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use WHICHC() instead of WHICHN() then.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documentations on functions are available here&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want ti book mark the formats and informats by category page (find them from the main documentation.sas.com page).&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723667#M224600</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T21:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723677#M224606</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;My variables ABC1 through ABC100 are defined as character ...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then why not use character functions (this code works for numeric variables as well):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if cats(of abc:)=repeat('1',99) then code=8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[Edit: Actually it's more robust for numeric variables because then the effect &lt;FONT face="courier new,courier"&gt;cats('11',' ')=cats('1','1')&lt;/FONT&gt; could not happen, assuming the standard setting of system option MISSING.]&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723677#M224606</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-04T21:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable based on a string of similar variables with identical responses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723720#M224636</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;My variables ABC1 through ABC100 are defined as character so I get an error.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Bad programmer! No cookie!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 23:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-based-on-a-string-of-similar-variables/m-p/723720#M224636</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T23:21:05Z</dc:date>
    </item>
  </channel>
</rss>

