<?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 How to use an Iterative Step and Format Multiple Variables Using MACRO in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307529#M61102</link>
    <description>&lt;P&gt;I have 4&amp;nbsp;string variables 'EMS_TC_ICD9_1 through EMS_TC_ICD9_4' . I want to aggreagate&amp;nbsp;them into larger cartegories and create 4&amp;nbsp;new group variables. &amp;nbsp;I thought using a MACRO would be more efficient &amp;nbsp;than running the Data Step 4&amp;nbsp;times but can't get it to run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I have no idea how to get the MACRO to recognize the PROC FORMAT or what's an alternate workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;END RESULT: I want to create 4&amp;nbsp;new numeric variables 'EMS_TC_ICD9_GRP1 through EMS_&lt;SPAN&gt;TC_ICD9_GRP4 and assign names to the different categories.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I didn't get any errors but this is definitely wrong - new variables were not created.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WHere did I go wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1922  options mprint nosymbolgen;
1923
1924  %MACRO ICD9(varnum, var, grpvar);
1925
1926  DATA TC_viaEMS_cleaning1;
1927  SET TC_viaEMS_cleaning;
1928
1929   %do i=1 %to &amp;amp;varnum;
1930
1931  %if EMS_TC_ICD9_&amp;amp;i="BL" or EMS_TC_ICD9_&amp;amp;i="*ND" %then %do;
1932     EMS_TC_ICD9_grp&amp;amp;i=.;
1933   %end;
1934
1935  %else %do;
1936  %if "800.00" le EMS_TC_ICD9_&amp;amp;i le "804.99" %then EMS_TC_ICD9_grp&amp;amp;i=1;
1937  %else %if "805.00" le EMS_TC_ICD9_&amp;amp;i le "809.99" %then EMS_TC_ICD9_grp&amp;amp;i=2;
1938  %else %if "810.00" le EMS_TC_ICD9_&amp;amp;i le "819.99" %then EMS_TC_ICD9_grp&amp;amp;i=3;
1939   %end;
1940
1941  %put EMS_TC_ICD9_grp&amp;amp;i  icdf.;
1942  run;
1943   %end;
1944
1945  %MEND ICD9;
1946  %ICD9(4, EMS_TC_ICD9_, EMS_TC_ICD9_grp);&lt;BR /&gt;
MPRINT(ICD9):   DATA TC_viaEMS_cleaning1;
MPRINT(ICD9):   SET TC_viaEMS_cleaning;
EMS_TC_ICD9_grp1  icdf.
MPRINT(ICD9):   run;

NOTE: There were 8921 observations read from the data set WORK.TC_VIAEMS_CLEANING.
NOTE: The data set WORK.TC_VIAEMS_CLEANING1 has 8921 observations and 49 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.06 seconds


EMS_TC_ICD9_grp2  icdf.
MPRINT(ICD9):   run;
EMS_TC_ICD9_grp3  icdf.
MPRINT(ICD9):   run;
EMS_TC_ICD9_grp4  icdf.
MPRINT(ICD9):   run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Oct 2016 00:09:07 GMT</pubDate>
    <dc:creator>eap</dc:creator>
    <dc:date>2016-10-27T00:09:07Z</dc:date>
    <item>
      <title>How to use an Iterative Step and Format Multiple Variables Using MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307529#M61102</link>
      <description>&lt;P&gt;I have 4&amp;nbsp;string variables 'EMS_TC_ICD9_1 through EMS_TC_ICD9_4' . I want to aggreagate&amp;nbsp;them into larger cartegories and create 4&amp;nbsp;new group variables. &amp;nbsp;I thought using a MACRO would be more efficient &amp;nbsp;than running the Data Step 4&amp;nbsp;times but can't get it to run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I have no idea how to get the MACRO to recognize the PROC FORMAT or what's an alternate workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;END RESULT: I want to create 4&amp;nbsp;new numeric variables 'EMS_TC_ICD9_GRP1 through EMS_&lt;SPAN&gt;TC_ICD9_GRP4 and assign names to the different categories.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I didn't get any errors but this is definitely wrong - new variables were not created.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WHere did I go wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1922  options mprint nosymbolgen;
1923
1924  %MACRO ICD9(varnum, var, grpvar);
1925
1926  DATA TC_viaEMS_cleaning1;
1927  SET TC_viaEMS_cleaning;
1928
1929   %do i=1 %to &amp;amp;varnum;
1930
1931  %if EMS_TC_ICD9_&amp;amp;i="BL" or EMS_TC_ICD9_&amp;amp;i="*ND" %then %do;
1932     EMS_TC_ICD9_grp&amp;amp;i=.;
1933   %end;
1934
1935  %else %do;
1936  %if "800.00" le EMS_TC_ICD9_&amp;amp;i le "804.99" %then EMS_TC_ICD9_grp&amp;amp;i=1;
1937  %else %if "805.00" le EMS_TC_ICD9_&amp;amp;i le "809.99" %then EMS_TC_ICD9_grp&amp;amp;i=2;
1938  %else %if "810.00" le EMS_TC_ICD9_&amp;amp;i le "819.99" %then EMS_TC_ICD9_grp&amp;amp;i=3;
1939   %end;
1940
1941  %put EMS_TC_ICD9_grp&amp;amp;i  icdf.;
1942  run;
1943   %end;
1944
1945  %MEND ICD9;
1946  %ICD9(4, EMS_TC_ICD9_, EMS_TC_ICD9_grp);&lt;BR /&gt;
MPRINT(ICD9):   DATA TC_viaEMS_cleaning1;
MPRINT(ICD9):   SET TC_viaEMS_cleaning;
EMS_TC_ICD9_grp1  icdf.
MPRINT(ICD9):   run;

NOTE: There were 8921 observations read from the data set WORK.TC_VIAEMS_CLEANING.
NOTE: The data set WORK.TC_VIAEMS_CLEANING1 has 8921 observations and 49 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.06 seconds


EMS_TC_ICD9_grp2  icdf.
MPRINT(ICD9):   run;
EMS_TC_ICD9_grp3  icdf.
MPRINT(ICD9):   run;
EMS_TC_ICD9_grp4  icdf.
MPRINT(ICD9):   run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2016 00:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307529#M61102</guid>
      <dc:creator>eap</dc:creator>
      <dc:date>2016-10-27T00:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an Iterative Step and Format Multiple Variables Using MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307532#M61104</link>
      <description>&lt;P&gt;Use an array not a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Or a format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/default_new.htm#new_vars" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/default_new.htm#new_vars&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 00:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307532#M61104</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-27T00:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an Iterative Step and Format Multiple Variables Using MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307548#M61106</link>
      <description>&lt;P&gt;Thanks Reeza, it worked perfectly!&amp;nbsp; Great reference document for arrays!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 02:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-an-Iterative-Step-and-Format-Multiple-Variables-Using/m-p/307548#M61106</guid>
      <dc:creator>eap</dc:creator>
      <dc:date>2016-10-27T02:53:35Z</dc:date>
    </item>
  </channel>
</rss>

