<?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: use the Marco to repeat code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529712#M144776</link>
    <description>&lt;P&gt;Learning to use Base SAS - the programming language - and its constructs will improve your code making it quicker, less resource hungry, more robust, and simpler to read.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;BR /&gt;I have a set of variables, all of which I need to do some processing on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Answer:&lt;/P&gt;
&lt;P&gt;Use arrays of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you have not shown test data input, or required output I cannot code this for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to your issue, it comes about due to bad coding practices.&amp;nbsp; You have not finished the macro variable invocation correctly using a decimal place, therefore the compiler is looking for a macro variable called: i_CompanyName to resolve to a value.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Follow good programming practice and always finish macro variables with a decimal place to avoid such issues!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;_PreviousName_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i._CompanyName&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do note however that use of arrays, and structuring your data in a usable method would remove the need for most of this code in the first place.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Jan 2019 15:34:19 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-01-24T15:34:19Z</dc:date>
    <item>
      <title>use the Marco to repeat code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529704#M144771</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to use the Marco&amp;nbsp;to repeat code,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to repeat a process 10 times by the following code,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro PreviousName;
%do i=1 %to 10;

data Sa_step2.House_company_base;
set Sa_step2.House_company_base;
_PreviousName_&amp;amp;i_CompanyName=upcase(_PreviousName_&amp;amp;i_CompanyName);
call scan(_PreviousName_&amp;amp;i_CompanyName, -1, position, length);
if scan(_PreviousName_&amp;amp;i_CompanyName,-1) in ('LTD' ,'LTD.','LIMITED.') then substr(_PreviousName_&amp;amp;i_CompanyName,position)='LIMITED';
drop position length;
run;

data sa_Step2.Patstat_gb_hrm;
set Step2.Patstat_gb_hrm;
rename PERSON_NAME=_PreviousName_&amp;amp;i_CompanyName;
run;

proc sort data=sa_Step2.Patstat_gb_hrm;
by _PreviousName_&amp;amp;i_CompanyName;
run;
proc sort data=Sa_step2.House_company_base;
by _PreviousName_&amp;amp;i_CompanyName;
run;

data STEP6.CompanyHouse_Patstat&amp;amp;i step4.Patstat_gb_hrm&amp;amp;i step3.CompanyHouse&amp;amp;i;
   merge Step2.Patstat_gb_hrm (in=ina)
         Sa_step2.House_company_base (in=inb)
   ;
   by _PreviousName_&amp;amp;i_CompanyName;
   if ina and inb then output STEP6.CompanyHouse_Patstat&amp;amp;i;
   else if ina then output step4.Patstat_gb_hrm&amp;amp;i;
   else if inb then output step3.CompanyHouse&amp;amp;i;
run;


%end;
%mend PreviousName;

%PreviousName
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;926  %macro PreviousName;
927  %do i=1 %to 10;
928
929  data Sa_step2.House_company_base;
930  set Sa_step2.House_company_base;
931  _PreviousName_&amp;amp;i_CompanyName =upcase(_PreviousName_&amp;amp;i_CompanyName);
932  call scan(_PreviousName_&amp;amp;i_CompanyName, -1, position, length);
933  if scan(_PreviousName_&amp;amp;i_CompanyName,-1) in ('LTD' ,'LTD.','LIMITED.') then
933! substr(_PreviousName_&amp;amp;i_CompanyName,position)='LIMITED';
934  drop position length;
935  run;
936
937  data sa_Step2.Patstat_gb_hrm;
938  set Step2.Patstat_gb_hrm;
939  rename PERSON_NAME=_PreviousName_&amp;amp;i_CompanyName;
940  run;
941
942  proc sort data=sa_Step2.Patstat_gb_hrm;
943  by _PreviousName_&amp;amp;i_CompanyName;
944  run;
945  proc sort data=Sa_step2.House_company_base;
946  by _PreviousName_&amp;amp;i_CompanyName;
947  run;
948
949  data STEP6.CompanyHouse_Patstat&amp;amp;i step4.Patstat_gb_hrm&amp;amp;i step3.CompanyHouse&amp;amp;i;
950     merge Step2.Patstat_gb_hrm (in=ina)
951           Sa_step2.House_company_base (in=inb)
952     ;
953     by _PreviousName_&amp;amp;i_CompanyName;
954     if ina and inb then output STEP6.CompanyHouse_Patstat&amp;amp;i;
955     else if ina then output step4.Patstat_gb_hrm&amp;amp;i;
956     else if inb then output step3.CompanyHouse&amp;amp;i;
957  run;
958
959
960  %end;
961  %mend PreviousName;
962
963  %PreviousName
NOTE: Line generated by the invoked macro "PREVIOUSNAME".
1      data Sa_step2.House_company_base; set Sa_step2.House_company_base; _PreviousName_&amp;amp;i_CompanyName
                                                                          --------------
                                                                          180
1  !  =upcase(_PreviousName_&amp;amp;i_CompanyName); call scan(_PreviousName_&amp;amp;i_CompanyName, -1, position,
1  ! length); if scan(_PreviousName_&amp;amp;i_CompanyName,-1) in ('LTD'
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
NOTE: Line generated by the invoked macro "PREVIOUSNAME".
2     ,'LTD.','LIMITED.') then substr(_PreviousName_&amp;amp;i_CompanyName,position)='LIMITED'; drop position
                                                    -
                                                    356
2  ! length; run;  data sa_Step2.Patstat_gb_hrm; set Step2.Patstat_gb_hrm; rename
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
ERROR: Argument to SUBSTR must be character.

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE 356-185: The SUBSTR pseudo-variable function does not allow character constants, expressions, or
              numeric constants for the first argument.

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      1:162   1:223
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set SA_STEP2.HOUSE_COMPANY_BASE may be incomplete.  When this step was stopped
         there were 0 observations and 57 variables.
WARNING: Data set SA_STEP2.HOUSE_COMPANY_BASE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.37 seconds
      cpu time            0.01 seconds



NOTE: Line generated by the invoked macro "PREVIOUSNAME".
2    data sa_Step2.Patstat_gb_hrm; set Step2.Patstat_gb_hrm; rename
2  ! PERSON_NAME=_PreviousName_&amp;amp;i_CompanyName; run;  proc sort
                               -
                               22
                               200
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
ERROR: Missing numeric suffix on a numbered variable list (_PreviousName_-i_CompanyName).
ERROR: Old and new variable name specifications for RENAME must be of the same type. Statement is
       ignored.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set SA_STEP2.PATSTAT_GB_HRM may be incomplete.  When this step was stopped there
         were 0 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.01 seconds


22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN
              where the error has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, :, DECENDING, DESCENDING,
              DESENDING, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
      the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
ERROR: Variable _PREVIOUSNAME_ not found.
ERROR: Variable I_COMPANYNAME not found.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds


22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN
              where the error has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, :, DECENDING, DESCENDING,
              DESENDING, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
      the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.
ERROR: Variable _PREVIOUSNAME_ not found.
ERROR: Variable I_COMPANYNAME not found.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds



NOTE: Line generated by the invoked macro "PREVIOUSNAME".
5     Step2.Patstat_gb_hrm (in=ina)          Sa_step2.House_company_base (in=inb)    ;    by
5  ! _PreviousName_&amp;amp;i_CompanyName;    if ina and inb then output STEP6.CompanyHouse_Patstat&amp;amp;i;    else
                   -
                   22
                   200
WARNING: Apparent symbolic reference I_COMPANYNAME not resolved.

ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, DESCENDING, GROUPFORMAT,
              NOTSORTED, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set STEP6.COMPANYHOUSE_PATSTAT1 may be incomplete.  When this step was stopped
         there were 0 observations and 61 variables.
WARNING: The data set STEP4.PATSTAT_GB_HRM1 may be incomplete.  When this step was stopped there were
         0 observations and 61 variables.
WARNING: The data set STEP3.COMPANYHOUSE1 may be incomplete.  When this step was stopped there were 0
         observations and 61 variables.
NOTE: DATA statement used (Total process time):
      real time           0.20 seconds
      cpu time            0.01 seconds

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;could you please give me some suggestions about it?&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529704#M144771</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2019-01-24T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: use the Marco to repeat code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529708#M144774</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must have the run inside the do loop, and also mention &amp;amp;i. (not the period at end)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mprint mlogic;
%macro PreviousName;
%do i=1 %to 10; 
data Sa_step2.House_company_base;
set Sa_step2.House_company_base;
_PreviousName_&amp;amp;i._CompanyName =upcase(_PreviousName_&amp;amp;i._CompanyName);
call scan(_PreviousName_&amp;amp;i._CompanyName, -1, position, length);
if scan(_PreviousName_&amp;amp;i._CompanyName,-1) in ('LTD' ,'LTD.','LIMITED.') then substr(_PreviousName_&amp;amp;i._CompanyName,position)='LIMITED';
drop position length;
run;
%end;
%mend PreviousName;

%PreviousName;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529708#M144774</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-01-24T15:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: use the Marco to repeat code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529712#M144776</link>
      <description>&lt;P&gt;Learning to use Base SAS - the programming language - and its constructs will improve your code making it quicker, less resource hungry, more robust, and simpler to read.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;BR /&gt;I have a set of variables, all of which I need to do some processing on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Answer:&lt;/P&gt;
&lt;P&gt;Use arrays of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you have not shown test data input, or required output I cannot code this for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to your issue, it comes about due to bad coding practices.&amp;nbsp; You have not finished the macro variable invocation correctly using a decimal place, therefore the compiler is looking for a macro variable called: i_CompanyName to resolve to a value.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Follow good programming practice and always finish macro variables with a decimal place to avoid such issues!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;_PreviousName_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i._CompanyName&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do note however that use of arrays, and structuring your data in a usable method would remove the need for most of this code in the first place.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-the-Marco-to-repeat-code/m-p/529712#M144776</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-24T15:34:19Z</dc:date>
    </item>
  </channel>
</rss>

