<?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 Set libname in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485563#M126170</link>
    <description>&lt;P&gt;I have a whole list of state abbreviations that are saved as libnames. I am trying to reference them in a simple macro to generate tables from data in each of these tables. All the files I in these libraries are of the form: state_commonname_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I had set up for this macro was:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want (state = , date = );
    data &amp;amp;state._history;
        set &amp;amp;state..&amp;amp;state._commonname_&amp;amp;date.;
    run;
%mend want;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example the table I am setting for Alabama would be&amp;nbsp;&lt;EM&gt;al.al_commonname_20180526&lt;/EM&gt;. Looks like the issue is stemming from the parsing of the periods in the set command.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2018 19:36:50 GMT</pubDate>
    <dc:creator>Ani7</dc:creator>
    <dc:date>2018-08-09T19:36:50Z</dc:date>
    <item>
      <title>Set libname in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485563#M126170</link>
      <description>&lt;P&gt;I have a whole list of state abbreviations that are saved as libnames. I am trying to reference them in a simple macro to generate tables from data in each of these tables. All the files I in these libraries are of the form: state_commonname_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I had set up for this macro was:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want (state = , date = );
    data &amp;amp;state._history;
        set &amp;amp;state..&amp;amp;state._commonname_&amp;amp;date.;
    run;
%mend want;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example the table I am setting for Alabama would be&amp;nbsp;&lt;EM&gt;al.al_commonname_20180526&lt;/EM&gt;. Looks like the issue is stemming from the parsing of the periods in the set command.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 19:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485563#M126170</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2018-08-09T19:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Set libname in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485566#M126171</link>
      <description>&lt;P&gt;I suspect that your getting bit by the tokenizer&amp;nbsp; macro interaction bug.&amp;nbsp; Your code will run fine outside of a macro. But inside a macro the dataset name looks like multiple words to SAS instead of just one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I like to do is build the name into a macro variable and then use that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want (state = , date = );
%local indsn outdsn;
%let indsn=&amp;amp;state..&amp;amp;state._commonname_&amp;amp;date.;
%let outdsn= &amp;amp;state._history;
    data &amp;amp;outdsn;
        set &amp;amp;indsn;
    run;
%mend want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also just wrap it in an %unquote() so that it is seen as a single token.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 19:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485566#M126171</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-09T19:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Set libname in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485574#M126172</link>
      <description>&lt;P&gt;So this is perfect and I'll mark it as the correct solution. I just had a follow up question. If I have a list of around 8 states for a given date, how would I go about adapting this code so that I can put the 8 states into a list and have the macro loop through those 8 states for a fixed date so that 8 separate tables are created?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I would want:&lt;BR /&gt;&lt;EM&gt;al.al_commonname_20180526&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;wv.wv_commonname_20180526&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;wa.wa_commonname_20180526,&amp;nbsp;&lt;/EM&gt;etc.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 19:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485574#M126172</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2018-08-09T19:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Set libname in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485585#M126173</link>
      <description>&lt;P&gt;do you want&amp;nbsp;_history created in WORK library or state(AL) library? Check for the extra period in data statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want (state =al , date =20180526 );
    data &amp;amp;state.._history;/* Looks like your missing a period here */
        set &amp;amp;state..&amp;amp;state._commonname_&amp;amp;date.;
    run;
%mend want;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Aug 2018 20:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-libname-in-a-macro/m-p/485585#M126173</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-08-09T20:06:30Z</dc:date>
    </item>
  </channel>
</rss>

