<?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 Can an array index increment by 2? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298122#M62661</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to use a SAS array to create variables for every second year &amp;nbsp;and then populate these variables. Using the example below, I'd like for the created variables to only include the even years from 1992 to 2006, for a total of 8 variables. Currently, I have to create variables for all years from 1992 to 2006, and then drop the odd numbered years.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't believe that a nested loop - where, for example, i = 1 to 8 - solves my problem, but please correct me if I am wrong. I think that I need the array index to only be factoring in values 1992, 1994, 1996, 1998 ...2006. This would allow the array index value to equal the _BASEYR&amp;nbsp;value for which I am evaluating the expression, and populate the correct item in the array with a TRUE/FALSE value.&amp;nbsp;Is it possible to specify an array index that precisely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	*CREATE THE CALENDAR YEARS;
	ARRAY FPB_CY (1992:2006) FPB_CY1992 - FPB_CY2006; 

	DO J = 1992 TO 2006 BY 2;
		IF _BASEYR = J THEN FPB_CY{J}= 1;
		ELSE FPB_CY{J} = 0;
	END;

	DROP FPB_CY1993 FPB_CY1995 FPB_CY1997 FPB_CY1999 FPB_CY2001 FPB_CY2003 FPB_CY2005;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Preeti&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2016 19:09:13 GMT</pubDate>
    <dc:creator>Lakhpreet</dc:creator>
    <dc:date>2016-09-13T19:09:13Z</dc:date>
    <item>
      <title>Can an array index increment by 2?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298122#M62661</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to use a SAS array to create variables for every second year &amp;nbsp;and then populate these variables. Using the example below, I'd like for the created variables to only include the even years from 1992 to 2006, for a total of 8 variables. Currently, I have to create variables for all years from 1992 to 2006, and then drop the odd numbered years.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't believe that a nested loop - where, for example, i = 1 to 8 - solves my problem, but please correct me if I am wrong. I think that I need the array index to only be factoring in values 1992, 1994, 1996, 1998 ...2006. This would allow the array index value to equal the _BASEYR&amp;nbsp;value for which I am evaluating the expression, and populate the correct item in the array with a TRUE/FALSE value.&amp;nbsp;Is it possible to specify an array index that precisely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	*CREATE THE CALENDAR YEARS;
	ARRAY FPB_CY (1992:2006) FPB_CY1992 - FPB_CY2006; 

	DO J = 1992 TO 2006 BY 2;
		IF _BASEYR = J THEN FPB_CY{J}= 1;
		ELSE FPB_CY{J} = 0;
	END;

	DROP FPB_CY1993 FPB_CY1995 FPB_CY1997 FPB_CY1999 FPB_CY2001 FPB_CY2003 FPB_CY2005;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Preeti&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 19:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298122#M62661</guid>
      <dc:creator>Lakhpreet</dc:creator>
      <dc:date>2016-09-13T19:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can an array index increment by 2?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298136#M62662</link>
      <description>&lt;P&gt;You can do it, but you might prefer the code you have now anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, your array would have to spell out the names of all 8 elements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array fpb_cy {8} fpb_cy1992 fpb_cy1994 fpb_cy1996 ... fpb_cy2006;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then your DO loop would become more difficult to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do j=1 to 8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if _baseyr = 1990 + 2*j then fpb_cy{j}=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else fpb_cy{j}=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what your are trying to achieve, it might be easier to create 8 observations, rather than a single observation with 8 new variables.&amp;nbsp; That's just to think about for the moment, since only you know where the analysis is headed.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 19:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298136#M62662</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-13T19:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can an array index increment by 2?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298186#M62681</link>
      <description>Thank you! I actually really like this solution. It's quite tidy and informative on how to use that same concept in other array situations. &lt;BR /&gt;</description>
      <pubDate>Wed, 14 Sep 2016 01:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-an-array-index-increment-by-2/m-p/298186#M62681</guid>
      <dc:creator>Lakhpreet</dc:creator>
      <dc:date>2016-09-14T01:16:18Z</dc:date>
    </item>
  </channel>
</rss>

