<?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: Do loop on a macro with Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552096#M153474</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I don't see where you are getting different results for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;nbvareer&lt;/FONT&gt; or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;nbvarev&amp;amp;i&lt;/FONT&gt; depending on whether or not &amp;amp;I is 1 or 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2; ;
ARRAY tev&amp;amp;i. &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_; ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in which case SAS figures out how many elements are in each array&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Aaaaaaaah ok... lol good to know... much easier indeed, I did not know that sas found the number of elements by himself..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much ^^&lt;/P&gt;</description>
    <pubDate>Thu, 18 Apr 2019 13:09:30 GMT</pubDate>
    <dc:creator>Onizuka</dc:creator>
    <dc:date>2019-04-18T13:09:30Z</dc:date>
    <item>
      <title>Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552072#M153465</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Sorry for my english)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create an array but using an extra condition if we are in the first loop of the "DO".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see here my code, I think I'm not very far from succeeding but I have a syntax problem in the macro language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO traitement_spe_idf ;
%DO i = 1 %TO 2 ;

data tempoidf&amp;amp;i;
	set mdv.ev&amp;amp;i._finale;
		if niveau_plus_grd = "17515";
		%let nbvareer = %eval(&amp;amp;nbvar_eer. +2);
		%let nbvarev&amp;amp;i. = %eval(&amp;amp;&amp;amp;nbvar_ev&amp;amp;i. +2);
			ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale.  %IF i = 1 %THEN  ceidfeer_1 ceidfeer_2 %str(;) ;
			ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ %str(;) ;

				do j=1 to dim(teer);
				teer[j]=tev&amp;amp;i.[j];
				end;

		%IF i = 1 %THEN %DO ;
			eer_q7=ceidfev1_2;
			eer_q6_i1_=.;
			eer_q6_i2_=.;
		%END ;

		%ELSE %DO ;
			eer_q7=ceidfev2_1;
			ceidfeer_1=ceidfev2_2;
			eer_q6_i1=.;
			eer_q6_i2=.;
			ceidfeer_2=.;
		%END ;
	drop j &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. &amp;amp;&amp;amp;list_ev&amp;amp;i._a_suppr.;
run;


%END ;

%MEND traitement_spe_idf ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem on this code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i'm generating the both arrays, i want to add 2 variables if I am on the first loop (i = 1) so i tried the %IF ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if you have any ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552072#M153465</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-18T12:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552075#M153467</link>
      <description>&lt;P&gt;Where do you set all those macro variables you are using, like&lt;/P&gt;
&lt;PRE&gt;&amp;amp;nbvar_eer&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552075#M153467</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-18T12:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552076#M153468</link>
      <description>&lt;P&gt;When you refer to&amp;nbsp; a macro variable like &amp;amp;I, you have to have &amp;amp;i in the %IF statement. Your code is missing the &amp;amp;. This is what it should look like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale.  %IF &amp;amp;i = 1 %THEN  ceidfeer_1 ceidfeer_2 %str(;) ;

ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ %str(;) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552076#M153468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T12:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552079#M153469</link>
      <description>&lt;P&gt;Okey, i'am going to try it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale.  %IF &amp;amp;i = 1 %THEN  ceidfeer_1 ceidfeer_2 %str(;) ;
	ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ %str(;) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think I have another problem that I will try to solve :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;nbvareer. contain the number of variable in &amp;amp;list_eer_finale. These macro variable were creating previously, i'm doing the code step by step, when all works, i'm putting the entire code on the %macro %mend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;nbvarev&lt;STRONG&gt;&amp;amp;i&lt;/STRONG&gt;. contains :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;number of variable in list_ev&lt;STRONG&gt;1&lt;/STRONG&gt;_finale (17 +2)&lt;/LI&gt;&lt;LI&gt;number of variable in list_ev&lt;STRONG&gt;2&lt;/STRONG&gt;_finale (17 &lt;STRIKE&gt;+2&lt;/STRIKE&gt;)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i think that i have a problem, because when i'm doing the second loop, i don't have the additionnal two variables so it's wrong. i am going to modify this point.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552079#M153469</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-18T12:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552085#M153470</link>
      <description>&lt;P&gt;The other problem in your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2 %str(;) ;
ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ %str(;) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When &amp;amp;i=2, then the %IF statements don't execute, and I don't think your ARRAY statements end with a semi-colon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2; ;
ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_; ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first semi-colon on each line ends the %IF, and the second semi-colon ends the ARRAY statement.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552085#M153470</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T12:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552093#M153471</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The other problem in your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2 %str(;) ;
ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ %str(;) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When &amp;amp;i=2, then the %IF statements don't execute, and I don't think your ARRAY statements end with a semi-colon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you want this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.] &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2; ;
ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_; ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The first semi-colon on each line ends the %IF, and the second semi-colon ends the ARRAY statement.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okey, I thought we had to put %str( ; ) for the %IF. Thank you for this precision. I'm trying now to resolve my second problem.&lt;BR /&gt;&lt;BR /&gt;On my first loop, I have 17 variables +2 but on the second one I only have 17 variables so I have to modify the&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[&amp;amp;nbvareer.]
ARRAY tev&amp;amp;i.[&amp;amp;&amp;amp;nbvarev&amp;amp;i.]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and more precisely my both macro variables !&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 12:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552093#M153471</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-18T12:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552094#M153472</link>
      <description>&lt;P&gt;I don't see where you are getting different results for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;nbvareer&lt;/FONT&gt; or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;nbvarev&amp;amp;i&lt;/FONT&gt; depending on whether or not &amp;amp;I is 1 or 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2; ;
ARRAY tev&amp;amp;i. &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_; ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in which case SAS figures out how many elements are in each array&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 13:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552094#M153472</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T13:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552095#M153473</link>
      <description>&lt;P&gt;I succeeded :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer[%IF &amp;amp;i = 1 %THEN %eval(&amp;amp;nbvar_eer. +2); %Else &amp;amp;nbvar_eer.;] &amp;amp;list_eer_finale.   %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2  ;;

ARRAY tev&amp;amp;i.[%IF &amp;amp;i = 1 %THEN %eval(&amp;amp;&amp;amp;nbvar_ev&amp;amp;i.+2); %Else &amp;amp;&amp;amp;nbvar_ev&amp;amp;i.;] &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_ ;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A little far-fetched but it works haha (i'm still learning about macro language and what you explained to me last time helps me a lot)&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 13:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552095#M153473</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-18T13:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop on a macro with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552096#M153474</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I don't see where you are getting different results for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;nbvareer&lt;/FONT&gt; or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;nbvarev&amp;amp;i&lt;/FONT&gt; depending on whether or not &amp;amp;I is 1 or 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY teer &amp;amp;list_eer_finale. %IF &amp;amp;i = 1 %THEN ceidfeer_1 ceidfeer_2; ;
ARRAY tev&amp;amp;i. &amp;amp;&amp;amp;list_ev&amp;amp;i._finale. %IF &amp;amp;i = 1 %THEN ceidfev1_1_i1_ ceidfev1_1_i2_; ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in which case SAS figures out how many elements are in each array&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Aaaaaaaah ok... lol good to know... much easier indeed, I did not know that sas found the number of elements by himself..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much ^^&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 13:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-on-a-macro-with-Array/m-p/552096#M153474</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-18T13:09:30Z</dc:date>
    </item>
  </channel>
</rss>

