<?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: Setting Libname for macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603233#M174785</link>
    <description>&lt;P&gt;You have the CALL to the macro before the DEFINITION of the macro, but let's just assume that was just a mistake in posting here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's do a quick review of the macro:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You are telling SAS where one of your macro variable names ends, but not the other.&amp;nbsp; So you are referencing a macro variable named CNCR_ that you have not defined instead of the CNCR parameter.&lt;/LI&gt;
&lt;LI&gt;You appear to be putting semi-colons in the middle of your SET statement.&amp;nbsp; To avoid this I recommend placing the ending semi-colon for multiple line statements on a new line instead of hiding it at the end of the last line.&amp;nbsp; This coding pattern will make it easier for you to notice this type of mistake.&lt;/LI&gt;
&lt;LI&gt;You have left the last data step open.&amp;nbsp; Are you intending to add more statements to that last data step after the call to the macro? If not then include the RUN: statement in the macro definition.&lt;/LI&gt;
&lt;LI&gt;You are using two different methods to address SAS datasets.&amp;nbsp; Sometimes you are defining a libref and using two level names and other times you are just using a quoted physical name.&amp;nbsp; Is there any reason you need to use both methods instead of just standardizing on one?&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro merge (cncr=, file= );

data clms; 
  set "Z:\dx2009\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2009"
      "Z:\dx2010\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2010"
      "Z:\dx2011\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2011"
  ;
run;

proc sql noprint;
create table "Z:\sasdata\&amp;amp;cncr.clm24maftbts_dx2009_2011" as 
  select * 
  from clms as A
    left join "Z:\sasdata\betoshcpcs" as B
      on a.hcpcs = b.hcpcs
  order by patient_id
;
quit;

%mend merge;

%merge (cncr = prst, file = nch); &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Nov 2019 15:01:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-11-11T15:01:27Z</dc:date>
    <item>
      <title>Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602975#M174643</link>
      <description>&lt;P&gt;I'm trying to set a libname step with a macro, which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%include "Z:\somelocation\somemacro.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%merge (name= varname, file= filename);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;endsas;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[include macro: somemacro.sas]&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options ps=max ls=232 nocenter nodate;&lt;/P&gt;&lt;P&gt;%macro merge (name = , file = );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname in1 ("Z:\date1\sasdata",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"Z:\date2\sasdata");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When running the program, in1 assigns appropriately but the macro variables don't "resolve":&lt;/P&gt;&lt;P&gt;"WARNING:&amp;nbsp; Apparent symbolic reference FILE not resolved"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I place the "in2" outside of the macro, the macro resolves but the "in2" library reference does not resolve. I've created several files using similar techniques (without error); it seems I'm missing a simple detail and would greatly appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&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;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 12:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602975#M174643</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-09T12:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602981#M174645</link>
      <description>&lt;P&gt;As the first line of your program, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run the program again, and paste the ENTIRE log (not just the error messages) as text (not a screen capture) in your reply by clicking on the &lt;FONT face="courier new,courier"&gt;{i}&lt;/FONT&gt; icon and pasting the log into the window that appears. &lt;STRONG&gt;Do not skip this step&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 13:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602981#M174645</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-09T13:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602985#M174647</link>
      <description>&lt;P&gt;stop trying to start with macros and get the process to work first.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 13:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602985#M174647</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-11-09T13:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602989#M174649</link>
      <description>&lt;P&gt;You have not really provided enough information to understand what code you are actually running.&lt;/P&gt;
&lt;P&gt;But most likely the error about macro variables not resolving is caused by you trying to reference macro variables that are LOCAL to the macro after the macro has finished running.&lt;/P&gt;
&lt;P&gt;For example that macro variable FILE in your %MERGE() macro is local (all macro parameters are local macro variables).&amp;nbsp; So you cannot do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%merge(file=FRED);
libname in2 "&amp;amp;file";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And expect IN2 to point to the 'FRED' directory.&amp;nbsp; If FILE existed before the call to %MERGE() then it will still have the same value after %MERGE() ends, it will NOT have been change to FRED. If there was no FILE macro variable then SAS will say it cannot find it and try to use the literal text '&amp;amp;file' as the path for the libname statement.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 16:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/602989#M174649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-09T16:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603211#M174774</link>
      <description>&lt;P&gt;Thanks Paige, I am running the program right now. Will post the results when it finishes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 14:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603211#M174774</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-11T14:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603212#M174775</link>
      <description>&lt;P&gt;Already did this&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 14:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603212#M174775</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-11T14:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603221#M174782</link>
      <description>&lt;P&gt;Hi Tom thanks for your advice. I had the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%merge (cncr = prst, file = nch); 

%macro merge (cncr=, file = );

libname in1 ("Z:\dx2009\sasdata",
                     "Z:\dx2010\sasdata",
                     "Z:\dx2011\sasdata");

data clms; 
  set in1.&amp;amp;cncr_&amp;amp;file.clm_dx2009; 
        in1.&amp;amp;cncr_&amp;amp;file.clm_dx2010; 
        in1.&amp;amp;cncr_&amp;amp;file.clm_dx2011; 

data bhcpcs; 
  set "Z:\sasdata\betoshcpcs";

proc sql noprint;
create table clm24maftbts as 
select * 
from clms as A
left join bhcpcs as B
on a.hcpcs = b.hcpcs
order by patient_id;
quit;

data "Z:\sasdata\&amp;amp;cncr.clm24maftbts_dx2009_2011";
  set clm24maftbts;

%mend merge;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2019 14:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603221#M174782</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-11T14:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603225#M174783</link>
      <description>&lt;PRE&gt;Here is the log. I had to make some modifications for privacy concerns. Thanks again for your help


The merge is in progress right now and the data but I peeked at the log file:
    
1          options ls=232 ps=max nocenter nodate mprint;
2          /******************************************************************/
3          /*                                                                */
4          /******************************************************************/
5          %include "Z:\sasmacro.pgms\prst.24maftclm.betosmerge.macro.sas";
69         
70            /************************/
71            /* prostate cancer      */
72            /************************/
73         %merge (cncr = prst, file = nch);
MPRINT(MERGE):   libname in1 ("Z:\dx2009\sasdata", "Z:\dx2010\sasdata", "Z:\dx2011\sasdata", "Z:\dx2012\sasdata", 
"Z:\dx2013\sasdata");
NOTE: Libref IN1 was successfully assigned as follows: 
      Levels:           5
      Engine(1):        V9 
      Physical Name(1): Z:\dx2009\sasdata
      Engine(2):        V9 
      Physical Name(2): Z:\dx2010\sasdata
      Engine(3):        V9 
      Physical Name(3): Z:\dx2011\sasdata
      Engine(4):        V9 
      Physical Name(4): Z:\dx2012\sasdata
      Engine(5):        V9 
      Physical Name(5): Z:\dx2013\sasdata
MPRINT(MERGE):   data clms;
MPRINT(MERGE):   set in1.prst_24maft_dx2009 in1.prst_24maft_dx2010 in1.prst_24maft_dx2011 in1.prst_24maft_dx2012;
 
NOTE: There were 390000 observations read from the data set IN1.PRST_24MAFT_DX2009.
NOTE: There were 3800000 observations read from the data set IN1.PRST_24MAFT_DX2010.
NOTE: There were 3900000 observations read from the data set IN1.PRST_24MAFT_DX2011.
NOTE: There were 3300000 observations read from the data set IN1.PRST_24MAFT_DX2012.
NOTE: The data set WORK.CLMS has 15000000 observations and 112 variables.
NOTE: DATA statement used (Total process time):
      real time           2:39.07
      cpu time            58.61 seconds
      
 
MPRINT(MERGE):   data bhcpcs;
MPRINT(MERGE):   set "Z:\sasdata\betoshcpcs";
 
NOTE: There were 16048 observations read from the data set Z:\sasdata\betoshcpcs.
NOTE: The data set WORK.BHCPCS has 16048 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.91 seconds
      cpu time            0.04 seconds&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2019 14:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603225#M174783</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-11T14:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603233#M174785</link>
      <description>&lt;P&gt;You have the CALL to the macro before the DEFINITION of the macro, but let's just assume that was just a mistake in posting here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's do a quick review of the macro:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You are telling SAS where one of your macro variable names ends, but not the other.&amp;nbsp; So you are referencing a macro variable named CNCR_ that you have not defined instead of the CNCR parameter.&lt;/LI&gt;
&lt;LI&gt;You appear to be putting semi-colons in the middle of your SET statement.&amp;nbsp; To avoid this I recommend placing the ending semi-colon for multiple line statements on a new line instead of hiding it at the end of the last line.&amp;nbsp; This coding pattern will make it easier for you to notice this type of mistake.&lt;/LI&gt;
&lt;LI&gt;You have left the last data step open.&amp;nbsp; Are you intending to add more statements to that last data step after the call to the macro? If not then include the RUN: statement in the macro definition.&lt;/LI&gt;
&lt;LI&gt;You are using two different methods to address SAS datasets.&amp;nbsp; Sometimes you are defining a libref and using two level names and other times you are just using a quoted physical name.&amp;nbsp; Is there any reason you need to use both methods instead of just standardizing on one?&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro merge (cncr=, file= );

data clms; 
  set "Z:\dx2009\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2009"
      "Z:\dx2010\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2010"
      "Z:\dx2011\sasdata\&amp;amp;cncr._&amp;amp;file.clm_dx2011"
  ;
run;

proc sql noprint;
create table "Z:\sasdata\&amp;amp;cncr.clm24maftbts_dx2009_2011" as 
  select * 
  from clms as A
    left join "Z:\sasdata\betoshcpcs" as B
      on a.hcpcs = b.hcpcs
  order by patient_id
;
quit;

%mend merge;

%merge (cncr = prst, file = nch); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2019 15:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603233#M174785</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-11T15:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603243#M174788</link>
      <description>Sorry for the confusion Tom.&lt;BR /&gt;(I did invert the macro/merge steps)&lt;BR /&gt;1) In modifying the code for privacy reasons, I also clipped the periods at the end of the var &amp;amp;cncr.&lt;BR /&gt;2) Yes, good advice&lt;BR /&gt;3) Yes, just a proc freq statement at the end of the program.&lt;BR /&gt;4) There is some inconsistency as I was trying to determine the source of the error.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Nov 2019 15:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603243#M174788</guid>
      <dc:creator>ryyno10</dc:creator>
      <dc:date>2019-11-11T15:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Libname for macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603247#M174790</link>
      <description>&lt;P&gt;SAS can confuse itself when you are trying to build one SAS "word" from multiple macro variables into thinking you have two words , or tokens, especially when you do it inside of a macro.&lt;/P&gt;
&lt;P&gt;Using the quoted physical names will help since the quoted string is passed by the macro processor onto SAS after all of the macro triggers are resolved.&lt;/P&gt;
&lt;P&gt;Otherwise I find that it just helps to build up complex dataset names, like in your example, into a new macro variable and then use that.&lt;/P&gt;
&lt;P&gt;For example you might want to introduce a %DO loop to generate the year by year dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xxx ....
%local year memname ;
...
SET
%do year = 2009 %to 2011 ;
  %let memname=&amp;amp;cncr._&amp;amp;file.clm_dx&amp;amp;year. ;
  in1.&amp;amp;memname
%end;
;
...
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2019 15:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-Libname-for-macro/m-p/603247#M174790</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-11T15:35:00Z</dc:date>
    </item>
  </channel>
</rss>

