<?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 Create a Macro List in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243526#M45287</link>
    <description>&lt;P&gt;Hello there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and am having difficulties completing an easy macro. I know how to run it in Stata (with the for var statement) but I seem to struggle trying to translate it to SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;am&amp;nbsp;working on a project where we have 50 datasets from all 50 states. We are given SAS files that automatically clean and compilate the flat-files for each state. So, I am trying to run a macro that cycles through all 50 states and opens up the SAS file associated with that state, runs it, and gives us a final dataset for that state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to create a working macro that allows me to call the other datasets:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro statecycle(abbr);&lt;BR /&gt;%include "C:\Users\ashland.PMACS\Desktop\Testing\&amp;amp;abbr.\SAS_test&amp;amp;abbr..sas" ;&lt;BR /&gt;%Mend statecycle;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am really struggling figuring out how to run a macro list that changes abbr to the a state. I tried everything from a let statement to importing a dataset with only the state abbreviations and trying to run an entire variable.Everything I've tried doesn't work, or maybe I'm on the right track I just have no idea what the codes are.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that in stata there is a "for var " statement where I can give it a list of names and associate that list with a letter (e.g. `x') and whenever I call on `x' in my code it cycles through all the names I gave it. I feel like there is a simple solution for SAS, I just haven't been able to figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thankful for any help or advice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jan 2016 17:49:18 GMT</pubDate>
    <dc:creator>ashdrews19</dc:creator>
    <dc:date>2016-01-14T17:49:18Z</dc:date>
    <item>
      <title>Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243526#M45287</link>
      <description>&lt;P&gt;Hello there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and am having difficulties completing an easy macro. I know how to run it in Stata (with the for var statement) but I seem to struggle trying to translate it to SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;am&amp;nbsp;working on a project where we have 50 datasets from all 50 states. We are given SAS files that automatically clean and compilate the flat-files for each state. So, I am trying to run a macro that cycles through all 50 states and opens up the SAS file associated with that state, runs it, and gives us a final dataset for that state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to create a working macro that allows me to call the other datasets:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro statecycle(abbr);&lt;BR /&gt;%include "C:\Users\ashland.PMACS\Desktop\Testing\&amp;amp;abbr.\SAS_test&amp;amp;abbr..sas" ;&lt;BR /&gt;%Mend statecycle;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am really struggling figuring out how to run a macro list that changes abbr to the a state. I tried everything from a let statement to importing a dataset with only the state abbreviations and trying to run an entire variable.Everything I've tried doesn't work, or maybe I'm on the right track I just have no idea what the codes are.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that in stata there is a "for var " statement where I can give it a list of names and associate that list with a letter (e.g. `x') and whenever I call on `x' in my code it cycles through all the names I gave it. I feel like there is a simple solution for SAS, I just haven't been able to figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thankful for any help or advice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 17:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243526#M45287</guid>
      <dc:creator>ashdrews19</dc:creator>
      <dc:date>2016-01-14T17:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243530#M45289</link>
      <description>&lt;P&gt;I think you're looking for a format to apply it to map the state abbrev to state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you may want to take a look into call execute for automating procedures from a data driven table.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 17:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243530#M45289</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-14T17:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243533#M45291</link>
      <description>&lt;P&gt;This won't give you all the answers, but it will help you start thinking in the right direction:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/" target="_blank"&gt;http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 17:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243533#M45291</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-14T17:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243536#M45292</link>
      <description>&lt;P&gt;Here's an example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data state_fmt;
set mapssas.us2;
start=statecode;
label=statename;
fmtname='$abbr2state';
type='C';
run;

proc format cntlin=state_fmt;
run;

%put %sysfunc(putc(AL, $abbr2state.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jan 2016 18:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243536#M45292</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-14T18:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243574#M45304</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to run the code, and I am a little confused as to what it would be doing. Is the format making the state names into abbreviations? Because my data is already in the abbreviated form. I'm just trying to figure out how to make a list of all 50 abbreviations and call all 50 variables when I run the macro I already have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying the code as such:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;%Let statename = AZ PA ... WA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;%Macro statecycle(abbr);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %include "C:\Users\ashland.PMACS\Desktop\Testing\&amp;amp;abbr.\SAS_test&amp;amp;abbr..sas" ;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;%Mend statecycle;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;%statecycle (&amp;amp;statename);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;However, a let statement doesn't allow me to do multiple items in a row.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 20:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243574#M45304</guid>
      <dc:creator>ashdrews19</dc:creator>
      <dc:date>2016-01-14T20:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243580#M45310</link>
      <description>&lt;P&gt;Then create a list and loop through it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select statecode into :state_list separated by " "
from mapssas.us2;
quit;

%put &amp;amp;state_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The blog link above illustrates looping through a list, though I really, really, really think you should look into call execute.&lt;/P&gt;
&lt;P&gt;Loop through macro variables - my example&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/9603186" target="_blank"&gt;https://gist.github.com/statgeek/9603186&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Call execute - look at the example. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table state_list as
select statecode from mapssas.us2;
quit;

*Add call execute to your macro here;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 20:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-List/m-p/243580#M45310</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-14T20:33:52Z</dc:date>
    </item>
  </channel>
</rss>

