<?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: How to handle % signs in macro variables. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948022#M371020</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When specifying:&lt;/P&gt;
&lt;PRE&gt;X "mkdir ""&amp;amp;sdtm_bckup_path""";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should you be using the following instead:&lt;/P&gt;
&lt;PRE&gt;X "mkdir ""&amp;amp;work_bckup_path""";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, then please post the full log using the insert code icon "&amp;lt;/&amp;gt;". Does it show the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;bckup_w&lt;/FONT&gt; library was allocated successfully?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2024 11:32:25 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2024-10-18T11:32:25Z</dc:date>
    <item>
      <title>How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948002#M371010</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm working on SAS 94.&lt;/P&gt;&lt;P&gt;My final goal is to put the following file path into a macro variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET sdtm_bckup_path =&amp;nbsp;&lt;/P&gt;&lt;P&gt;%NRSTR(%RXC_SAS_DATA%)&amp;amp;DL.%NRSTR(&amp;amp;UNIXDIR.)&amp;amp;DL.%NRSTR(&amp;amp;mrocf.)&amp;amp;DL.%NRSTR(&amp;amp;sdtm.)&amp;amp;DL.&amp;amp;dttm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, it's populated by % signs and &amp;amp; signs.&lt;BR /&gt;I tried to use both %NRSTR and %NRBQUOTE; the first function works in case "%RXC_SAS_DATA" with only one % sign.&lt;BR /&gt;Any idea how to handle "%RXC_SAS_DATA%" or just "%" ?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 07:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948002#M371010</guid>
      <dc:creator>OGA13</dc:creator>
      <dc:date>2024-10-18T07:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948010#M371014</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321116"&gt;@OGA13&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried something like (double % signs):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var = %nrstr(%%text%%);
%put &amp;amp;=var;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for which the log shows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 72         %let var = %nrstr(%%text%%);
 73         %put &amp;amp;=var;
 VAR=%text%
 74         
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above does not help then what resulting string do you want to see when you reference macro variable &lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;sdtm_bckup_path&lt;/FONT&gt;?&amp;nbsp;&lt;/SPAN&gt;I'm unclear if you want any ampersands ("&amp;amp;") in the final string.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks &amp;amp; kind regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 09:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948010#M371014</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-10-18T09:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948014#M371015</link>
      <description>&lt;P&gt;/* Create a Datetime macro variable */&lt;BR /&gt;%LET dttm = %SYSFUNC( DATE(), yymmdd10. )T%SYSFUNC( TRANSLATE( %SYSFUNC( TIME(), tod8.), %STR(-),%STR(:) ) );&lt;BR /&gt;%LET sdtm_path = %NRSTR(%RXC_SAS_DATA%%)&amp;amp;DL.&amp;amp;UNIXDIR.&amp;amp;DL.&amp;amp;mrocf.&amp;amp;DL.&amp;amp;sdtm.;&lt;BR /&gt;&lt;BR /&gt;i'm sharing the full macro:&lt;BR /&gt;&lt;BR /&gt;/* Create a new &amp;lt;SDTM&amp;gt; sub-directory */&lt;BR /&gt;%LET sdtm_bckup_path = %NRSTR(%RXC_SAS_DATA%%)&amp;amp;DL.&amp;amp;UNIXDIR.&amp;amp;DL.&amp;amp;mrocf.&amp;amp;DL.&amp;amp;sdtm.&amp;amp;DL.&amp;amp;dttm;&lt;/P&gt;&lt;P&gt;*SET OPTIONS XWAIT=ON;&lt;BR /&gt;&lt;BR /&gt;/* Create the backup directory */&lt;BR /&gt;X "mkdir ""&amp;amp;sdtm_bckup_path""";&lt;BR /&gt;*X "echo ""&amp;amp;sdtm_bckup_path""";&lt;/P&gt;&lt;P&gt;/* Copy files from the SDTM path to the backup path*/&lt;BR /&gt;X "copy ""&amp;amp;sdtm_path&amp;amp;DL.*.*"" ""&amp;amp;sdtm_bckup_path""";&lt;BR /&gt;&lt;BR /&gt;Double %% sign did actually solved the problem. To make it more clear, i'm sending&amp;nbsp; the string to the command line; therefore i want the ampersand to be resolved.&lt;/P&gt;&lt;P&gt;I tried to remove the unneeded %nrstr() function, but it still seems to fail.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 09:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948014#M371015</guid>
      <dc:creator>OGA13</dc:creator>
      <dc:date>2024-10-18T09:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948017#M371016</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please respond to the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;What value do you want to see when macro variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sdtm_bckup_path&amp;nbsp;&lt;/FONT&gt;is resolved?&lt;/LI&gt;
&lt;LI&gt;Please show the error you are getting.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks &amp;amp; kind regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 10:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948017#M371016</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-10-18T10:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948021#M371019</link>
      <description>&lt;P&gt;1. That's the desired path:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%LET sdtm_path = %NRSTR(%RXC_SAS_DATA%%)&amp;amp;DL.&amp;amp;UNIXDIR.&amp;amp;DL.&amp;amp;mrocf.&amp;amp;DL.&amp;amp;sdtm.;

%put &amp;amp;sdtm_path;
%RXC_SAS_DATA%\unixdir\mrocf\SDTM&lt;/PRE&gt;&lt;P&gt;2. The actual error is given by another macro which uses the macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* 4) Backup WORK folder*/
  
  %LET work_bckup_path =%NRSTR(%RXC_SAS_DATA%%)&amp;amp;DL.&amp;amp;UNIXDIR.&amp;amp;DL.&amp;amp;mrocf.&amp;amp;DL.wbckup ;
  
  X "mkdir ""&amp;amp;sdtm_bckup_path""";

  LIBNAME bckup_w  "&amp;amp;work_bckup_path" ;

  PROC DATASETS LIB=bckup_w KILL NOLIST MEMTYPE=data ; 
  QUIT ;

  PROC DATASETS ;
	COPY IN  = work
	     OUT = bckup_w memtype= data ;
  RUN ;
  QUIT ;

  %logmsg( level = I, 
        function = HOR_START, 
         message = %STR( Backup WORK folder ),
          action = C ) ; 

INFO: (HOR_START) - Backup options including SASAUTOS
%RXC_SAS_DATA%\unixdir\mrocf\mapping\bckup
INFO: (HOR_START) - Backup SDTM folder
WARNING: Library BCKUP_W does not exist.
ERROR: Library BCKUP_W does not exist.

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 10:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948021#M371019</guid>
      <dc:creator>OGA13</dc:creator>
      <dc:date>2024-10-18T10:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948022#M371020</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When specifying:&lt;/P&gt;
&lt;PRE&gt;X "mkdir ""&amp;amp;sdtm_bckup_path""";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should you be using the following instead:&lt;/P&gt;
&lt;PRE&gt;X "mkdir ""&amp;amp;work_bckup_path""";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, then please post the full log using the insert code icon "&amp;lt;/&amp;gt;". Does it show the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;bckup_w&lt;/FONT&gt; library was allocated successfully?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 11:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948022#M371020</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-10-18T11:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948028#M371021</link>
      <description>It worked, thanks a lot!</description>
      <pubDate>Fri, 18 Oct 2024 11:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948028#M371021</guid>
      <dc:creator>OGA13</dc:creator>
      <dc:date>2024-10-18T11:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948030#M371022</link>
      <description>&lt;P&gt;I can possibly see why you might need the % characters in that string since it looks like you might be running on Windows and what to reference an environment variable using the %NAME% syntax of Windows/DOS operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why would you want to also include &amp;amp; characters?&amp;nbsp; Do your directory names actual have &amp;amp; characters in them?&amp;nbsp; It does not look like that is what you are trying to describe.&amp;nbsp; Instead it just looks like you are building a string by expanding a lot of already defined macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing I would do is move the&amp;nbsp;&lt;SPAN&gt;%RXC_SAS_DATA% to its own macro variable so its value can be macro quoted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let topdir=%str(%%RXC_SAS_DATA%%);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Then you can build the desired path using something like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let topdir=%str(%%RXC_SAS_DATA%%);
%let DL = \ ;
%let UNIXDIR=fred ;
%let mrocf=XXX;
%let sdtm=AE ;
%let DTTM=202410180759;
%LET sdtm_bckup_path = &amp;amp;topdir&amp;amp;dl&amp;amp;unixdir&amp;amp;dl&amp;amp;mrocf&amp;amp;dl&amp;amp;sdtm&amp;amp;dl&amp;amp;dttm;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;And if you want to get the value of an environment variable you can use SYSGET or %SYSGET.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let topdir=%sysget(RXC_SAS_DATA);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If you need it macro quoted use %QSYSFUNC() to call the actual SYSGET() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let topdir=%qsysfunc(sysget(RXC_SAS_DATA));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Oct 2024 12:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948030#M371022</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-18T12:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle % signs in macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948073#M371029</link>
      <description>&lt;P&gt;A couple of other points.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use single quotes around a value to prevent the macro processor from evaluating the macro triggers (% and &amp;amp;). You can then use %qsysfunc(dequote()) to get the value out of quotes and apply macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%qsysfunc(dequote('%ENVAR%\R&amp;amp;D Department\'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general it is better to use a PIPE to run operating system commands.&amp;nbsp; That way you can see the error messages.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "mkdir ""&amp;amp;sdtm_bckup_path""" pipe;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which means you can then use that data step to manipulate your strings and not have to worry about the macro processor trying to evaluate the value of the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length cmd $400;
  cmd = catx(' ','mkdir',quote(trim(symget('sdtm_bckup_path'))));
  infile cmd pipe filevar=cmd ;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 15:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-handle-signs-in-macro-variables/m-p/948073#M371029</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-18T15:36:22Z</dc:date>
    </item>
  </channel>
</rss>

