<?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: How to iterate over columns to find the first instance greater than a designated value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438053#M282318</link>
    <description>&lt;P&gt;You have to stop the loop from continuing to execute when you find a value &amp;gt; 1000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

do i=1 to dim(months);
    if months{i}&amp;gt;1000 then do;
        first_month=vname(months{i}) ;
        leave;
    end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2018 19:51:15 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-02-16T19:51:15Z</dc:date>
    <item>
      <title>How to iterate over columns to find the first instance greater than a designated value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438052#M282317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set that I am using has a ID column and then the next 120 columns&amp;nbsp;contain the monthly data from every month for the last 10 years. For each ID, I need to be able to create a column that determines the first month that the value for that month is greater than or equal to a value that I designate. If there are no months for that id that are greater than the designated value, then I need to exclude that&amp;nbsp;ID from the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example of what my data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data example;&lt;BR /&gt; input id jan2007 feb2007 mar2007;&lt;BR /&gt; cards;&lt;BR /&gt; 1 1000 2000 3000&lt;BR /&gt; 2 . 500 1000&lt;BR /&gt; 3 100 100 100&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; In this example, my desired outcome if I was looking for all values &amp;gt;=1000 would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;id jan2007 feb2007 mar2007 first_month&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jan2007&lt;/P&gt;&lt;P&gt;2&amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mar2007&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying to use an array pick out the first time that the value is greater than 1000 for each id. After a while of searching the forums I have gotten so close to figuring it out, but the loop I created picks out the last instance where the do loop is greater than 1000 not the first. The code that I have so far is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outtest;
set example;
array months {*} jan2018--mar2008;
do i=1 to dim(months);
	if months{i}&amp;gt;1000 then first_month=vname(months{i}) ;
end;
run;

data outtest2;
set outtest;
if first_month='' then delete;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This gives me;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;id jan2008 feb2008 mar2008 first_month&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mar2008&lt;/P&gt;&lt;P&gt;2&amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mar2008&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If somebody would be able to help me figure out how to change my code so that it would give me the first instance where the value of the month is &amp;gt;=1000&amp;nbsp;I would really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for the help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 19:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438052#M282317</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2018-02-16T19:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate over columns to find the first instance greater than a designated value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438053#M282318</link>
      <description>&lt;P&gt;You have to stop the loop from continuing to execute when you find a value &amp;gt; 1000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

do i=1 to dim(months);
    if months{i}&amp;gt;1000 then do;
        first_month=vname(months{i}) ;
        leave;
    end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 19:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438053#M282318</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-02-16T19:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate over columns to find the first instance greater than a designated value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438054#M282319</link>
      <description>&lt;P&gt;That was so easy, I was so close to having it.Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 19:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438054#M282319</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2018-02-16T19:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate over columns to find the first instance greater than a designated value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438055#M282320</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
 input id jan2007 feb2007 mar2007;
 cards;
 1 1000 2000 3000
 2 . 500 1000
 3 100 100 100
;
run;

data want;
set example;
array t(*) jan2007--mar2007;
do _n_=1 to dim(t);
if t{_n_}&amp;gt;=1000 then do;
first_month=vname(t{_n_}) ;
output;
return;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Feb 2018 19:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iterate-over-columns-to-find-the-first-instance-greater/m-p/438055#M282320</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-16T19:55:35Z</dc:date>
    </item>
  </channel>
</rss>

