<?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: Calculating length of variables part 2 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588594#M14813</link>
    <description>1. Use FINDC() to return the position of the first 1.&lt;BR /&gt;2. Use REVERSE()  + FINDC() to find the position of the last 1. Use 6 - this value to get the actual position. &lt;BR /&gt;3. Use SUBSTR() and #1/#2 to get the middle code and then use FIND() to search for 00 in the string. &lt;BR /&gt;&lt;BR /&gt;So you just need some SAS basic string functions. &lt;BR /&gt;&lt;BR /&gt;Functions are documented here:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodsle&amp;amp;docsetTarget=syntaxByType-function.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodsle&amp;amp;docsetTarget=syntaxByType-function.htm&amp;amp;locale=en&lt;/A&gt;</description>
    <pubDate>Fri, 13 Sep 2019 17:13:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-09-13T17:13:16Z</dc:date>
    <item>
      <title>Calculating length of variables part 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588593#M14812</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another problem with calculating differences in lengths between 2 variables.&lt;/P&gt;&lt;P&gt;For example, I have a field called 'Emp' with 6 characters as follows;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;010111&lt;/P&gt;&lt;P&gt;111001&lt;/P&gt;&lt;P&gt;101010&lt;/P&gt;&lt;P&gt;100010&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate the length between the first appearance of a '1' and the last appearance of a '1' for each row. However, if we have a string of at &lt;STRONG&gt;least&lt;/STRONG&gt; two zeros in between the first and last 1 for each row, I want to classify this observation as 'Unclassified'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The anwers should be 4 (for the 1st row), 'Unclassifed' (for the 2nd row), 4 (for the 3rd row) and 'Unclassified' (for the 4th row).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can somebody please help out with a code to automate this process?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks (again)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588593#M14812</guid>
      <dc:creator>zishaq</dc:creator>
      <dc:date>2019-09-13T17:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of variables part 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588594#M14813</link>
      <description>1. Use FINDC() to return the position of the first 1.&lt;BR /&gt;2. Use REVERSE()  + FINDC() to find the position of the last 1. Use 6 - this value to get the actual position. &lt;BR /&gt;3. Use SUBSTR() and #1/#2 to get the middle code and then use FIND() to search for 00 in the string. &lt;BR /&gt;&lt;BR /&gt;So you just need some SAS basic string functions. &lt;BR /&gt;&lt;BR /&gt;Functions are documented here:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodsle&amp;amp;docsetTarget=syntaxByType-function.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodsle&amp;amp;docsetTarget=syntaxByType-function.htm&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588594#M14813</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-13T17:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of variables part 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588601#M14814</link>
      <description>&lt;PRE&gt;if index(variable,'00') &amp;gt; 0 then &amp;lt;however you are indicating unclassified&amp;gt;;
Else &amp;lt;the approach chosen earlier to find the first/last combination&amp;gt;;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588601#M14814</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-13T17:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of variables part 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588607#M14815</link>
      <description>&lt;P&gt;You already got an answer to part 1, along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
first=findc(str,'1');
last=findc(str,'1','b');
want=last-first;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For part 2, add one last statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(substr(str, first, want), '00') then want = .U;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that WANT is defined as numeric.&amp;nbsp; So it can't store "unclassified" as its value.&amp;nbsp; But it can store a special missing value (.U) to indicate that it fits into that category.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-length-of-variables-part-2/m-p/588607#M14815</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-13T17:36:11Z</dc:date>
    </item>
  </channel>
</rss>

