<?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 Counting Horizontal backwards in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794169#M81528</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking at counting variables backwards from a start point&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below examples shows what we have. I am looking at these 13 variables and hoping to count backwards to see how many Y's are consecutive from point 13 working backwards. E.g. ID1 = 1 as after this it hits a N, ID2 = 0 as Y comes after this point and ID 3 = 5.&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input ID (var1-var13)($);&lt;BR /&gt;cards;&lt;BR /&gt;1 Y Y N N Y Y Y N Y Y Y N Y&lt;BR /&gt;2 Y Y Y Y Y Y Y Y Y Y N N N&lt;BR /&gt;3 Y N N N N Y N N Y Y Y Y Y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final Dataset is shown below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input ID (var1-var13)($) Consecutive_Y_from_Var13;&lt;BR /&gt;cards;&lt;BR /&gt;1 Y Y N N Y Y Y N Y Y Y N Y 1&lt;BR /&gt;2 Y Y Y Y Y Y Y Y Y Y N N N 0&lt;BR /&gt;3 Y N N N N Y N N Y Y Y Y Y 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be great,&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 09:00:00 GMT</pubDate>
    <dc:creator>Mick_bill</dc:creator>
    <dc:date>2022-02-03T09:00:00Z</dc:date>
    <item>
      <title>Counting Horizontal backwards</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794169#M81528</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking at counting variables backwards from a start point&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below examples shows what we have. I am looking at these 13 variables and hoping to count backwards to see how many Y's are consecutive from point 13 working backwards. E.g. ID1 = 1 as after this it hits a N, ID2 = 0 as Y comes after this point and ID 3 = 5.&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input ID (var1-var13)($);&lt;BR /&gt;cards;&lt;BR /&gt;1 Y Y N N Y Y Y N Y Y Y N Y&lt;BR /&gt;2 Y Y Y Y Y Y Y Y Y Y N N N&lt;BR /&gt;3 Y N N N N Y N N Y Y Y Y Y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final Dataset is shown below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input ID (var1-var13)($) Consecutive_Y_from_Var13;&lt;BR /&gt;cards;&lt;BR /&gt;1 Y Y N N Y Y Y N Y Y Y N Y 1&lt;BR /&gt;2 Y Y Y Y Y Y Y Y Y Y N N N 0&lt;BR /&gt;3 Y N N N N Y N N Y Y Y Y Y 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be great,&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 09:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794169#M81528</guid>
      <dc:creator>Mick_bill</dc:creator>
      <dc:date>2022-02-03T09:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Horizontal backwards</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794170#M81529</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (var1-var13)($);
cards;
1 Y Y N N Y Y Y N Y Y Y N Y
2 Y Y Y Y Y Y Y Y Y Y N N N
3 Y N N N N Y N N Y Y Y Y Y
;
run;

data want(drop = c);
   set have;
   c = cats(of var:);
   Consecutive_Y_from_Var13 = lengthn(scan(c, -1, 'N'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Feb 2022 09:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794170#M81529</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-03T09:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Horizontal backwards</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794172#M81530</link>
      <description>&lt;P&gt;SAS has arrays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (var1-var13)($);
cards;
1 Y Y N N Y Y Y N Y Y Y N Y
2 Y Y Y Y Y Y Y Y Y Y N N N
3 Y N N N N Y N N Y Y Y Y Y
;
run;

data want;
  set have;
  array A{*} var1-var13;

  Consecutive_Y_from_Var13 = 0;
  do _N_ = dim(A) to 1 by -1;
    if a[_N_] = "N" then leave;
                    else Consecutive_Y_from_Var13 + 1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 09:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Horizontal-backwards/m-p/794172#M81530</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-02-03T09:23:07Z</dc:date>
    </item>
  </channel>
</rss>

