<?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: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777765#M247501</link>
    <description>&lt;P&gt;+1 for Tom's tip of using a&amp;nbsp;&lt;STRONG&gt;FILENAME&lt;/STRONG&gt; statement to indicate a folder. I use this all of the time as I have some programs that use different paths whether I run them on my local machine (Windows) or on a central server (Linux).&amp;nbsp; Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let tgtpath = %sysfunc(ifc(&amp;amp;SYSSCP. = WIN,
  \\network\root\u\&amp;amp;sysuserid.\.creds,
  /u/&amp;amp;sysuserid./.creds)
  );
filename creds "&amp;amp;tgtpath.";
%include creds(signon.sas);&lt;/LI-CODE&gt;
&lt;P&gt;Note that the quotes are not required for the "member name" you're including here.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Nov 2021 19:40:45 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2021-11-01T19:40:45Z</dc:date>
    <item>
      <title>Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777756#M247494</link>
      <description>&lt;P&gt;I am creating a Main program to execute 5 sub programs, and I want to reuse a file path for better code management.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;LIBNAME home 'C:\Users\user\Documents' ;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;%LET path = C:\Users\user\Documents&amp;nbsp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And later I have 5 INCLUDE statements as such:&lt;/P&gt;&lt;P&gt;%INCLUDE 'C:\Users\user\Documents\program01.sas' ;&lt;/P&gt;&lt;P&gt;%INCLUDE 'C:\Users\user\Documents\program02.sas' ;&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;Is there a way to use a LIBNAME or variable instead of having to use 'C:\Users\user\Documents' over and over? Such as:&lt;/P&gt;&lt;P&gt;$INCLUDE '&amp;amp;path\program01.sas' ;&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I've had no luck with using either a variable or LIBNAME, both give me errors. Ultimately, I want to be able to use the LIBNAME, variable or whatever to update the file path for all sub programs. Currently I have 5 subs and likely to have more in the future, so this would make code management a lot easier.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 19:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777756#M247494</guid>
      <dc:creator>jcromwell77</dc:creator>
      <dc:date>2021-11-01T19:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777757#M247495</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Such as:&lt;/P&gt;
&lt;P&gt;$INCLUDE '&amp;amp;path\program01.sas' ;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You type the INCLUDE command with a % sign not a $ sign. It should also use double quotes instead of single quotes.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 19:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777757#M247495</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-01T19:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777760#M247496</link>
      <description>&lt;P&gt;The macro processor will ignore strings that are quoted on the outside with single quote characters.&amp;nbsp; If you want the macro variable to be expanded then use double quote characters instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET path = C:\Users\user\Documents ;
%INCLUDE "&amp;amp;path\program01.sas" ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Libnames are for storing SAS datasets (or other binary SAS files like catalog), not for referencing text files.&amp;nbsp; If you want to make a nickname to point to directory for finding text files then use a FILENAME statement to define a fileref you can then use with your %INCLUDE, INFILE or FILE statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename root "C:\Users\user\Documents" ;
%INCLUDE root("program01.sas");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Editor's note: adding other helpful replies.&lt;/EM&gt;&amp;nbsp;This one from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%LET path = C:\Users\user\Documents ;

%INCLUDE "&amp;amp;path.\program01.sas";
%INCLUDE "&amp;amp;path.\program02.sas";&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Just as an FYI you can also wildcard your %includes using an *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "&amp;amp;path/Program0*.sas" / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;+1 for Tom's tip of using a&amp;nbsp;&lt;STRONG&gt;FILENAME&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;statement to indicate a folder. I use this all of the time as I have some programs that use different paths whether I run them on my local machine (Windows) or on a central server (Linux).&amp;nbsp; Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let tgtpath = %sysfunc(ifc(&amp;amp;SYSSCP. = WIN,
  \\network\root\u\&amp;amp;sysuserid.\.creds,
  /u/&amp;amp;sysuserid./.creds)
  );
filename creds "&amp;amp;tgtpath.";
%include creds(signon.sas);&lt;/LI-CODE&gt;
&lt;P&gt;Note that the quotes are not required for the "member name" you're including here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 02 Nov 2021 13:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777760#M247496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-02T13:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777761#M247497</link>
      <description>You're correct, and I fat-fingered the include statement. I meant %INCLUDE not $INCLUDE, and it is correct in my code, just not in my question above.</description>
      <pubDate>Mon, 01 Nov 2021 19:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777761#M247497</guid>
      <dc:creator>jcromwell77</dc:creator>
      <dc:date>2021-11-01T19:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777762#M247498</link>
      <description>Just as an FYI you can also wildcard your %includes using an *&lt;BR /&gt;&lt;BR /&gt;%include "&amp;amp;path/Program0*.sas" / source2;&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Nov 2021 19:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777762#M247498</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-01T19:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777763#M247499</link>
      <description>Thank you! I did not know about filename, and I used the syntax you gave me and was able to execute the code properly.</description>
      <pubDate>Mon, 01 Nov 2021 19:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777763#M247499</guid>
      <dc:creator>jcromwell77</dc:creator>
      <dc:date>2021-11-01T19:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777764#M247500</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET path = C:\Users\user\Documents ;

%INCLUDE "&amp;amp;path.\program01.sas";
%INCLUDE "&amp;amp;path.\program02.sas";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Nov 2021 19:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777764#M247500</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-01T19:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777765#M247501</link>
      <description>&lt;P&gt;+1 for Tom's tip of using a&amp;nbsp;&lt;STRONG&gt;FILENAME&lt;/STRONG&gt; statement to indicate a folder. I use this all of the time as I have some programs that use different paths whether I run them on my local machine (Windows) or on a central server (Linux).&amp;nbsp; Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let tgtpath = %sysfunc(ifc(&amp;amp;SYSSCP. = WIN,
  \\network\root\u\&amp;amp;sysuserid.\.creds,
  /u/&amp;amp;sysuserid./.creds)
  );
filename creds "&amp;amp;tgtpath.";
%include creds(signon.sas);&lt;/LI-CODE&gt;
&lt;P&gt;Note that the quotes are not required for the "member name" you're including here.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 19:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777765#M247501</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-11-01T19:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using LIBNAME or variable (%LET statement) in %INCLUDE statement for code reuse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777766#M247502</link>
      <description>Thank you, this worked as well. I wish I could add this as a solution too.</description>
      <pubDate>Mon, 01 Nov 2021 19:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-LIBNAME-or-variable-LET-statement-in-INCLUDE-statement-for/m-p/777766#M247502</guid>
      <dc:creator>jcromwell77</dc:creator>
      <dc:date>2021-11-01T19:41:19Z</dc:date>
    </item>
  </channel>
</rss>

