<?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: Resolving Macro but Not Environment Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550388#M152812</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173881"&gt;@Junyong&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p14ppks96uz65an1l5uq3elm0m3y.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SYSGET function&lt;/A&gt; to put the environment variable into a true macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let drive=%sysfunc(sysget(SystemDrive)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same can be done for username or use the builtin SAS macro variable &amp;amp;sysuserid.&amp;nbsp; That should get you error free code to use inside a macro or libname double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let drive=%sysfunc(sysget(SystemDrive)); 
libname desk "&amp;amp;drive\Users\&amp;amp;sysuserid\desk";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In Windows, there should also be a %USERPROFILE% environment variable you can grab which has the full path in one string, ie:&amp;nbsp; C:\users\username&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Apr 2019 19:55:59 GMT</pubDate>
    <dc:creator>DaveHorne</dc:creator>
    <dc:date>2019-04-11T19:55:59Z</dc:date>
    <item>
      <title>Resolving Macro but Not Environment Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550363#M152803</link>
      <description>&lt;P&gt;I often assign a library DESK as follows.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DESK '%SystemDrive%\Users\%USERNAME%\Desktop\';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I avoid the following as SAS tries to resolve environment variables inside double quotes.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DESK "%SystemDrive%\Users\%USERNAME%\Desktop\";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since there are many directories, I used macro variables and fed them to LIBNAME.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DESK %SystemDrive%\Users\%USERNAME%\Desktop\;
libname DESK '&amp;amp;DESK.';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, SAS does not resolve macro variables inside single quotes, so I need to use double quotes instead.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DESK "&amp;amp;DESK.";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is not safe as SAS tries to resolve both macro (ex. DESK) and environment variables (ex. SystemDrive, USERNAME). It also spits out many warning messages as byproducts. Is there any way not to resolve environment variables in macro variables while resolving? I also tried the following but failed.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DESK %tslit(&amp;amp;DESK.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 19:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550363#M152803</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-11T19:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro but Not Environmental Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550371#M152807</link>
      <description>Can you retrieve your environmental variables using some other character such as a dollar sign?  Why are you locked in to using macro language triggers?</description>
      <pubDate>Thu, 11 Apr 2019 19:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550371#M152807</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-11T19:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro but Not Environment Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550388#M152812</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173881"&gt;@Junyong&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p14ppks96uz65an1l5uq3elm0m3y.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SYSGET function&lt;/A&gt; to put the environment variable into a true macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let drive=%sysfunc(sysget(SystemDrive)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same can be done for username or use the builtin SAS macro variable &amp;amp;sysuserid.&amp;nbsp; That should get you error free code to use inside a macro or libname double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let drive=%sysfunc(sysget(SystemDrive)); 
libname desk "&amp;amp;drive\Users\&amp;amp;sysuserid\desk";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In Windows, there should also be a %USERPROFILE% environment variable you can grab which has the full path in one string, ie:&amp;nbsp; C:\users\username&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 19:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550388#M152812</guid>
      <dc:creator>DaveHorne</dc:creator>
      <dc:date>2019-04-11T19:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro but Not Environment Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550398#M152813</link>
      <description>&lt;P&gt;That style of %VARNAME% is a WINDOWS only construct. If you use that you are limiting your program to only be able to run on WIndows operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use the %SYSGET() macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also SAS uses the exclamation point to reference environment variables in operating system commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename home '%HOMEDRIVE%\%HOMEPATH%';
%put %sysfunc(pathname(home));
filename home "%sysget(HOMEDRIVE)\%sysget(HOMEPATH)";
%put %sysfunc(pathname(home));
filename home "!HOMEDRIVE\!HOMEPATH";
%put %sysfunc(pathname(home));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;2452  filename home '%HOMEDRIVE%\%HOMEPATH%';
2453  %put %sysfunc(pathname(home));
H:\
2454  filename home "%sysget(HOMEDRIVE)\%sysget(HOMEPATH)";
2455  %put %sysfunc(pathname(home));
H:\
2456  filename home "!HOMEDRIVE\!HOMEPATH";
2457  %put %sysfunc(pathname(home));
H:\
&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Apr 2019 20:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-Macro-but-Not-Environment-Variables/m-p/550398#M152813</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-11T20:12:15Z</dc:date>
    </item>
  </channel>
</rss>

