<?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: Question about macro language in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551328#M153170</link>
    <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for you answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I'm starting to understand how the macro works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took a code I had in which I repeated several times the same instruction but with different variables. I used the macro language to "reduce" the code as you can see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_hierarchie ;
set mdv.hierarchie ;
          _COD_ETB = input(COD_ETB, $15.);
_COD_EDS_EXTR_NIV1 = input(COD_EDS_EXTR_NIV1, $15.);
_COD_EDS_EXTR_NIV2 = input(COD_EDS_EXTR_NIV2, $15.);
_COD_EDS_EXTR_NIV3 = input(COD_EDS_EXTR_NIV3, $15.);
_COD_EDS_EXTR_NIV4 = input(COD_EDS_EXTR_NIV4, $15.);
_COD_EDS_EXTR_NIV5 = input(COD_EDS_EXTR_NIV5, $15.);
_COD_EDS_EXTR_NIV6 = input(COD_EDS_EXTR_NIV6, $15.);
_COD_EDS_EXTR_NIV7 = input(COD_EDS_EXTR_NIV7, $15.);
_COD_EDS_EXTR_NIV8 = input(COD_EDS_EXTR_NIV8, $15.);
 		  _LIB_ETB = put(LIB_ETB, $50.);
 _LIB_EDS_INT_NIV1 = put(LIB_EDS_INT_NIV1,$50.) ;
 _LIB_EDS_INT_NIV2 = put(LIB_EDS_INT_NIV2,$50.) ; 
 _LIB_EDS_INT_NIV3 = put(LIB_EDS_INT_NIV3,$50.) ;
 _LIB_EDS_INT_NIV4 = put(LIB_EDS_INT_NIV4,$50.) ;
 _LIB_EDS_INT_NIV5 = put(LIB_EDS_INT_NIV5,$50.) ;
 _LIB_EDS_INT_NIV6 = put(LIB_EDS_INT_NIV6,$50.) ;
 _LIB_EDS_INT_NIV7 = put(LIB_EDS_INT_NIV7,$50.) ;
 _LIB_EDS_INT_NIV8 = put(LIB_EDS_INT_NIV8,$50.) ;
run ;

Proc sql ;
create table test_hierarchie1 as
select 
	 NBNIV,
	 CleEDS,
	 _LIB_ETB as lib_plus_grd,
	 _LIB_EDS_INT_NIV1 as lniv1,
	 _LIB_EDS_INT_NIV2 as lniv2,
	 _LIB_EDS_INT_NIV3 as lniv3,
	 _LIB_EDS_INT_NIV4 as lniv4,
	 _LIB_EDS_INT_NIV5 as lniv5,
	 _LIB_EDS_INT_NIV6 as lniv6,
	 _LIB_EDS_INT_NIV7 as lniv7,
	 _LIB_EDS_INT_NIV8 as lniv8,

	 _COD_ETB as niveau_plus_grd,
	 _COD_EDS_EXTR_NIV1 as cniv1,
	 _COD_EDS_EXTR_NIV2 as cniv2,
	 _COD_EDS_EXTR_NIV3 as cniv3,
	 _COD_EDS_EXTR_NIV4 as cniv4,
	 _COD_EDS_EXTR_NIV5 as cniv5,
	 _COD_EDS_EXTR_NIV6 as cniv6,
	 _COD_EDS_EXTR_NIV7 as cniv7,
	 _COD_EDS_EXTR_NIV8 as cniv8
from test_hierarchie ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(These two codes are in a macro.)&lt;/P&gt;&lt;P&gt;I have transformed these two codes like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test (keep = nbniv cleEDS lib_plus_grd lniv: niveau_plus_grd cniv:);
Set mdv.hierarchie ;

	%do i = 1 %to 8 ;

		_COD_EDS_EXTR_NIV&amp;amp;i = input(COD_EDS_EXTR_NIV&amp;amp;i, $15.);

		_LIB_EDS_INT_NIV&amp;amp;i = put(LIB_EDS_INT_NIV&amp;amp;i,$50.) ;

		rename _LIB_EDS_INT_NIV&amp;amp;i = lniv&amp;amp;i ;

		rename _COD_EDS_EXTR_NIV&amp;amp;i = cniv&amp;amp;i ;

	%end ;

   		_COD_ETB = input(COD_ETB, $15.);

		_LIB_ETB = put(LIB_ETB, $50.);

		rename _COD_ETB = niveau_plus_grd ;

		rename _LIB_ETB = lib_plus_grd ;		 
run ;


data test1 ;
retain nbniv cleEDS lib_plus_grd lniv1-lniv8 niveau_plus_grd cniv1-cniv8 ;
set test ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is this a good use of macro ? (I don't ask you to rewrite my code but just tell if the use of macro language is appropriate here).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Apr 2019 09:14:51 GMT</pubDate>
    <dc:creator>Onizuka</dc:creator>
    <dc:date>2019-04-16T09:14:51Z</dc:date>
    <item>
      <title>Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/550989#M153030</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on SAS Macros and I saw that sometimes, we have to put&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%THEN %DO.....&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but sometimes we don't have to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA mdv.&amp;amp;typequest._finale (where = (test &amp;lt;&amp;gt; 0)) ;
	SET mdv.&amp;amp;typequest._finale;
	ARRAY tquestcourt[&amp;amp;nbvar.] &amp;amp;list.;
	test=0;
	%LOCAL i ;
	%DO i=1 %TO &amp;amp;nbvar.;
		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ;
	%END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;On this example, there is a %do i ... %to but just below there isn't a %if %then %do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't find specific rules on the web so I would like to ask the question here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/550989#M153030</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T12:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/550992#M153031</link>
      <description>&lt;P&gt;%DO and %IF are independent, one does not have to follow the other, you use them as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code you show, there is no need for a macro %DO here, and it won't work as you have coded it anyway. You can use a data step DO to loop over the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMPORTANT CONCEPT: get code to work properly first, one one iteration through a small data set, without macros; and then and only then add in macros and macro variables. Since you can get this code to work without %DO by using the data step DO, no need for macros.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/550992#M153031</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T12:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551001#M153033</link>
      <description>&lt;P&gt;Would you please provide an example of working code where a &lt;FONT face="courier new,courier"&gt;%do&lt;/FONT&gt; is followed by a &lt;FONT face="courier new,courier"&gt;%then&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 11:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551001#M153033</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-04-15T11:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551003#M153035</link>
      <description>&lt;P&gt;You typically wouldn't have %do followed by %then.&amp;nbsp; You will often see %then followed by %do, e.g.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if &amp;lt;condition&amp;gt; %then %do;
  *something;
%end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote, the %DO statement is a separate statement than the %IF/%THEN/%ELSE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are plenty of examples in the documentation, see e.g.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1xhuzfc68jkhcn1xb0c4d5atq5e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1xhuzfc68jkhcn1xb0c4d5atq5e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 11:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551003#M153035</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-04-15T11:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551007#M153038</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Would you please provide an example of working code where a &lt;FONT face="courier new,courier"&gt;%do&lt;/FONT&gt; is followed by a &lt;FONT face="courier new,courier"&gt;%then&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think code can have %DO followed by %THEN.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551007#M153038</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T12:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551010#M153039</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;not sure if you meant to respond to me or the OP(?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it was me then agreed, which is why I asked the OP for a working example, as that was their opening assertion, so either they find an example, which someone on this forum should be able to explain to the OP, or they don't, in which case part of the premise of the question does not hold true and so the OP realises their assumption. Win-Win!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551010#M153039</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-04-15T12:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551012#M153040</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;agreed. Please see my initial response to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551012#M153040</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-04-15T12:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551013#M153041</link>
      <description>&lt;P&gt;Hello Miller, thank you for you response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before start doing "macro programm" i'm always doing without macro (like you said).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a little surprise by what you say because the programm works well !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This one allows to keep the observations for which at least one variable in the list is not null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551013#M153041</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T12:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551014#M153042</link>
      <description>&lt;P&gt;I don't have an example of that, the example i have is which one I post on the topic :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%DO i=1 %TO &amp;amp;nbvar.;
		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ;
	%END;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can see the %DO ... %TO and just below an IF (without percent before) ... THEN (without percent before) do (without percent before) so I was wondering why sometimes we put the %(IF, THEN, DO) and why sometimes not. Just after the %DO i = 1 %to &amp;amp;nbvar. ; there is a IF THEN DO without percent but as I am in macro language i found it weird.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT : This example is from a "long" macro programm&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551014#M153042</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T12:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551015#M153043</link>
      <description>&lt;P&gt;I agree, the %DO comes always after the %THEN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT : my bad, i write it bad on my exemple, i wanted to say %THEN ... %DO and not say %DO ... %THEN&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551015#M153043</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T12:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551020#M153046</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I was wondering why sometimes we put the %(IF, THEN, DO) and why sometimes not&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because sometimes the logic of the specific program requires it, and other times the logic does not require it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551020#M153046</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T12:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551022#M153047</link>
      <description>&lt;P&gt;Yes, I guess it depends.. buy why in my example (it's just an example of a code I have and run well) if i replace&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF tquestcourt[&amp;amp;i] ne . THEN do ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;by&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF tquestcourt[&amp;amp;i] ne . %THEN %DO ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it doesn't work while i'm in a macro programm. I don't understand very well the logic you are talking about.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551022#M153047</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T13:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551023#M153048</link>
      <description>&lt;P&gt;Typically, macro code is executed before any data step code is executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) The &lt;FONT face="courier new,courier"&gt;%do - %end&lt;/FONT&gt; loop will cause the data step code to be repeated &lt;FONT face="courier new,courier"&gt;&amp;amp;nbvar&lt;/FONT&gt; times.&lt;/P&gt;&lt;P&gt;2) Once the macro code has completed then the data step code will start, which include &lt;FONT face="courier new,courier"&gt;&amp;amp;nbvar&lt;/FONT&gt; instances of the &lt;FONT face="courier new,courier"&gt;if-then-do-end&lt;/FONT&gt; code.&lt;/P&gt;&lt;P&gt;3) Using &lt;FONT face="courier new,courier"&gt;options mprint;&lt;/FONT&gt; before you run the code should show more information in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551023#M153048</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-04-15T13:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551029#M153049</link>
      <description>&lt;P&gt;Okay,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269468"&gt;@Onizuka&lt;/a&gt;&amp;nbsp;we are going around in circles here. At one point, you seem to be asking questions about macro code, and then at other times you seem to be asking questions about the logic. Which is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your code doesn't work, then show us the SAS log, using options mprint; before you run the program. Look at the log yourself and see if you can figure out what is the problem. If not, then post the log here by clicking on the {i} icon and pasting it into the window that appears. Do not -- I repeat DO NOT -- post the log without clicking on the {i} icon and pasting it into the window that appears.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551029#M153049</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T13:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551030#M153050</link>
      <description>&lt;P&gt;Thank you Amir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that I have understood. When using a variable macro the % must be used and if not removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I could have written this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* if i take off the macro variable */
%macro test ;
..
Data blabla;
set blabla1 ;
..      
	DO i=1 TO 10;
		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ;
	END;
..
run ;

%mend test ;

/*if i add the macro variable */ 

%macro test ;
..
Data blabla ;
set blabla1 ;
..

	%DO i=1 %TO &amp;amp;nbvar.; 
		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ; 
	%END;
..
run ;

%mend test ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I right ? haha&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551030#M153050</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T13:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551034#M153053</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269468"&gt;@Onizuka&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Amir,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe that I have understood. When using a variable macro the % must be used and if not removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I could have written this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* if i take off the macro variable */	
%macro test ;&lt;BR /&gt;....&lt;BR /&gt;Data blabla;&lt;BR /&gt;set blabla1&lt;BR /&gt;...        &lt;BR /&gt;DO i=1 TO 10;
		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ;
	END;
...&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;%mend test ;

/*if i add the macro variable */

	%DO i=1 %TO &amp;amp;nbvar.;
 		IF tquestcourt[&amp;amp;i] ne . THEN do ; 
		test=test+1; 
		end ;
	%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Am I right ? haha&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is absolutely no benefit to adding a macro %DO loop here when you could and should use the data step DO loop.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551034#M153053</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T13:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551036#M153055</link>
      <description>&lt;P&gt;If you want to write MACRO logic then you use the macro commands: %IF, %DO etc.&lt;/P&gt;
&lt;P&gt;If you want to write SAS logic then you use the SAS commands: IF, DO etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor will execute the macro logic and the resulting code (text) will be sent to SAS to interpret and execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When thinking about what macro logic does think about it in terms of what CODE it generates.&lt;/P&gt;
&lt;P&gt;When thinking about what SAS logic does think about it in term of what DATA It generates.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551036#M153055</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-15T13:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551037#M153056</link>
      <description>&lt;P&gt;Ok, it also worked by removing the % .. I'm a little lost i have to admit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that when we are in a macro program we must put % everywhere&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551037#M153056</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T13:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551044#M153061</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269468"&gt;@Onizuka&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ok, it also worked by removing the % .. I'm a little lost i have to admit&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Data steps work just fine without any % signs. You need to become 100% clear about what the difference between macro code and data step code is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language results in text substitution. It replace some text (for example, &amp;amp;I) with its value (for example, 3). You don't need text substitution here, because everything written in data step language in this case works properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As stated earlier, get the program to work on one example or one iteration without macros and without macro variables. Then only add macros if what you need can't be done any other way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%IF&lt;/SPAN&gt; tquestcourt&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%THEN&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%DO&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the %IF means that the macro processor now is NOT looking for data step variables and their values. It does not know the value of TQUESTCOURT. It thinks that &lt;FONT face="courier new,courier"&gt;tquestcourt[&amp;amp;i] ne .&lt;/FONT&gt; is some text string, and it does not use the data set variable values. That is why you must use IF and not %IF here.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I thought that when we are in a macro program we must put % everywhere&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A terrible concept, that will mislead you and cause many problems in your future. Never think this way again. Please think about the concepts that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and I and others have stated here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551044#M153061</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-15T13:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Question about macro language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551045#M153062</link>
      <description>&lt;P&gt;Ok, so when we are in a Data step, we don't need to use %DO %IF etc. We should use the macro language when we are NOT in a data step. You agree ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like on this macro I have created which permit to execute my "long" macro programm :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO RUN_CIM_EER_EV (typequest =);

%LET date_fin_trim_precedent = %SYSFUNC(mdy(&amp;amp;mois_fin_trim_precedent.,&amp;amp;jour_fin_trim_precedent.,&amp;amp;annee_fin_trim_precedent.));
%LOCAL i ;
%DO i = 1 %TO %SYSFUNC(countw(&amp;amp;typequest));

%LET nextvar 	= %SCAN(&amp;amp;typequest, &amp;amp;i);		

			%CIM_EER_EV (typequest 				  = &amp;amp;nextvar
						,chemin_fichier			  = &amp;amp;chemin_fichier
						,jour_fin_trim_precedent  = &amp;amp;jour_fin_trim_precedent
						,mois_fin_trim_precedent  = &amp;amp;mois_fin_trim_precedent
						,annee_fin_trim_precedent = &amp;amp;annee_fin_trim_precedent)
	
%END ;

%MEND RUN_CIM_EER_EV ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-macro-language/m-p/551045#M153062</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-15T13:44:55Z</dc:date>
    </item>
  </channel>
</rss>

