<?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 macro variable created using %LET statement in LIBNAME statement inside a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765137#M242344</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;! This works! I was omitting quotation mark in the libname statement.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Aug 2021 18:27:04 GMT</pubDate>
    <dc:creator>SWEETSAS</dc:creator>
    <dc:date>2021-08-31T18:27:04Z</dc:date>
    <item>
      <title>Use macro variable created using %LET statement in LIBNAME statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765128#M242336</link>
      <description>&lt;P&gt;I want to use %LET statement to create a macro variable that holds a directory name. And then use the macro variable created in the %LET statement in a LIBNAME statement inside a macro.&amp;nbsp; This is giving me error.&amp;nbsp; See example below. Thanks for your help in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dir=C:\data\check;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro rpt(dsn=, sortby=);&lt;/P&gt;
&lt;P&gt;libname mylib %BQUOTE(%STR(&amp;amp;dir));&lt;/P&gt;
&lt;P&gt;proc sort data=mylib.&amp;amp;dsn out=dsnout;&lt;BR /&gt;by &amp;amp;sortby;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print data=dsnsout;&lt;BR /&gt;run;&lt;BR /&gt;%mend rpt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%rpt(dsn=motor,sortorder=cars)&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 17:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765128#M242336</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2021-08-31T17:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro variable created using %LET statement in LIBNAME statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765131#M242338</link>
      <description>&lt;P&gt;Why so complicated?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir=C:\data\check;

libname mylib "&amp;amp;dir.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will do it.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 17:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765131#M242338</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-31T17:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro variable created using %LET statement in LIBNAME statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765132#M242339</link>
      <description>&lt;P&gt;First, when executing the macro, you must specify the same arguments as when the macro is defined. So when executing the macro, you give an argument named SORTORDER, which does not exist when you defined the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, macros and macro variables create SAS code when the program runs. The code create by the macro or macro variable must be legal valid working SAS code. If it is not legal valid working SAS code, then the macro will not run. This macro creates the SAS code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mylib C:\data\check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is incorrect. What do you need to do to the above line to fix it and make it work? (Please answer without referring to macro variables or macros, please)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, when debugging macro, run this command before you execute the macro.&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;&amp;nbsp;For even more detailed debugging, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 18:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765132#M242339</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-31T18:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro variable created using %LET statement in LIBNAME statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765135#M242342</link>
      <description>&lt;UL&gt;
&lt;LI&gt;The macro is defined with DSN and &lt;FONT color="#FF9900"&gt;SORTBY&lt;/FONT&gt; but then use &lt;FONT color="#FF0000"&gt;SORTORDER&lt;/FONT&gt; not &lt;FONT color="#FF9900"&gt;SORTBY&lt;/FONT&gt; in the macro call.&lt;/LI&gt;
&lt;LI&gt;The %BQUOTE doesn't do what you think here, using double quotes is sufficient in this context&lt;/LI&gt;
&lt;LI&gt;It also has dsnout versus dsn&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;s&lt;/STRONG&gt;&lt;/FONT&gt;out in the PROC PRINT&lt;/LI&gt;
&lt;/UL&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;*create fake data to test;
libname mylib "/home/fkhurshed/Demo1/";

data mylib.cars;
set sashelp.cars;
run;

libname mylib;


*actual work;
*macro debugging options;
options mprint symbolgen;
%let dir=/home/fkhurshed/Demo1/;


%macro rpt(dsn=, sortby=);

libname mylib "&amp;amp;dir";

proc sort data=mylib.&amp;amp;dsn out=dsnout;
by &amp;amp;sortby;
run;

proc print data=dsnout (obs=10);
run;

%mend rpt;

 

%rpt(dsn=cars, sortby=origin)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15889"&gt;@SWEETSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to use %LET statement to create a macro variable that holds a directory name. And then use the macro variable created in the %LET statement in a LIBNAME statement inside a macro.&amp;nbsp; This is giving me error.&amp;nbsp; See example below. Thanks for your help in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dir=C:\data\check;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro rpt(dsn=, sortby=);&lt;/P&gt;
&lt;P&gt;libname mylib %BQUOTE(%STR(&amp;amp;dir));&lt;/P&gt;
&lt;P&gt;proc sort data=mylib.&amp;amp;dsn out=dsnout;&lt;BR /&gt;by &amp;amp;sortby;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print data=dsnsout;&lt;BR /&gt;run;&lt;BR /&gt;%mend rpt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%rpt(dsn=motor,sortorder=cars)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 18:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765135#M242342</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-31T18:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro variable created using %LET statement in LIBNAME statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765137#M242344</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;! This works! I was omitting quotation mark in the libname statement.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 18:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-variable-created-using-LET-statement-in-LIBNAME/m-p/765137#M242344</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2021-08-31T18:27:04Z</dc:date>
    </item>
  </channel>
</rss>

