<?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 Percent Sign in X Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678702#M204883</link>
    <description>&lt;P&gt;Thanks—resolving the environment variable in SAS beforehand worked. I am actually using a external software other than notepad.exe, but my problem was related to the environment variable issue. I posted this as a minimum working example because notepad.exe is common.&lt;/P&gt;</description>
    <pubDate>Sat, 22 Aug 2020 21:48:23 GMT</pubDate>
    <dc:creator>Junyong</dc:creator>
    <dc:date>2020-08-22T21:48:23Z</dc:date>
    <item>
      <title>Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678695#M204877</link>
      <description>&lt;P&gt;Suppose I want to open a text file &lt;EM&gt;have.txt&lt;/EM&gt; using &lt;EM&gt;notepad.exe&lt;/EM&gt; in SAS. Then, the code is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x notepad c:\users\junyong\desktop\have.txt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I found that using environment variables (percent signs) as follows causes an error—not in SAS but in &lt;EM&gt;notepad.exe&lt;/EM&gt;.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x notepad %userprofile%\desktop\have.txt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What should I do to properly pass the percent signs and, therefore, the environment variables in this case?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 20:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678695#M204877</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-22T20:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678696#M204878</link>
      <description>&lt;P&gt;Not sure I understand what error you are having.&amp;nbsp; How is it causing trouble for Notepad?&amp;nbsp; Does the environment variable not get resolved?&amp;nbsp; Are you sure the environment variable exists?&amp;nbsp; Does the value of the environment variable contain spaces?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try adding double quotes for Windows to recognize the name as a single string.&amp;nbsp; Also add single quotes to prevent SAS from trying to execute a macro named USERPROFILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'notepad "%userprofile%\desktop\have.txt"';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 20:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678696#M204878</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-22T20:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678699#M204880</link>
      <description>&lt;P&gt;&lt;CODE&gt;%userprofile%&lt;/CODE&gt; surely exists and is a Windows environment variable. It contains no space currently—&lt;CODE&gt;c:\users\junyong\&lt;/CODE&gt;.&lt;/P&gt;&lt;P&gt;The first code—with no percent sign—executes &lt;CODE&gt;notepad.exe&lt;/CODE&gt; and opens &lt;CODE&gt;c:\users\junyong\desktop\have.txt&lt;/CODE&gt; correctly.&lt;/P&gt;&lt;P&gt;I want to shorten the full path using the existing Windows environment variable &lt;CODE&gt;%userprofile%&lt;/CODE&gt; (therefore, &lt;CODE&gt;%userprofile%\desktop\have.txt&lt;/CODE&gt;).&lt;/P&gt;&lt;P&gt;The second code—with percent signs—executes &lt;CODE&gt;notepad.exe&lt;/CODE&gt; but fails to find &lt;CODE&gt;c:\users\junyong\desktop\have.txt&lt;/CODE&gt;.&lt;/P&gt;&lt;P&gt;Instead, if there exists &lt;CODE&gt;c:\program files\sashome\sasfoundation\9.4\%userprofile%\desktop\have.txt&lt;/CODE&gt;, which is weird, then the &lt;CODE&gt;notepad.exe&lt;/CODE&gt; opens it.&lt;/P&gt;&lt;P&gt;How can I make SAS pass the correct path to &lt;CODE&gt;notepad.exe&lt;/CODE&gt; rather than the weird path using X statements?&lt;/P&gt;&lt;P&gt;I tried your suggestion with quotation marks but failed to open the file again.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678699#M204880</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-22T21:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678700#M204881</link>
      <description>&lt;P&gt;Try using the %SYSGET() macro, or SYSGET() function to find the value of USERPROFILE.&lt;/P&gt;
&lt;P&gt;First check if USERPROFILE exists and what value it has.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Length of USERPROFILE is $sysfunc(envlen(USERPROFILE)).;
%put Value of USERPROFILE is %sysget(USERPROFILE).;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then try using it in your X command:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x notepad %sysget(USERPROFILE)\desktop\have.txt;
x "notepad %sysget(USERPROFILE)\desktop\have.txt";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also why are you running NOTEPAD on the file?&amp;nbsp; If you want to read why not just read it?&amp;nbsp; If you want to edit it why not just edit it in the program editor (or the "enhanced" program editor) of Display Manager?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678700#M204881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-22T21:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678701#M204882</link>
      <description>&lt;P&gt;Looks like the shell used by the X statement does not resolve the userprofile environment variable.&lt;/P&gt;
&lt;P&gt;Run zhe command with a filename pipe and stderr redirection:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe 'notepad %userprofile%\desktop\have.txt 2&amp;gt;&amp;amp;1';

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and see if the log provides a clue.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678701#M204882</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-22T21:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678702#M204883</link>
      <description>&lt;P&gt;Thanks—resolving the environment variable in SAS beforehand worked. I am actually using a external software other than notepad.exe, but my problem was related to the environment variable issue. I posted this as a minimum working example because notepad.exe is common.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678702#M204883</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-22T21:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678703#M204884</link>
      <description>&lt;P&gt;Unlike &lt;CODE&gt;x&lt;/CODE&gt;, &lt;CODE&gt;pipe&lt;/CODE&gt; works well. For example,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	infile "notepad %userprofile%\desktop\asdf.txt" pipe;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;executes &lt;CODE&gt;notepad.exe&lt;/CODE&gt; and opens the &lt;CODE&gt;asdf.txt&lt;/CODE&gt; correctly.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678703#M204884</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-22T21:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Percent Sign in X Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678704#M204885</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173881"&gt;@Junyong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks—resolving the environment variable in SAS beforehand worked. I am actually using a external software other than notepad.exe, but my problem was related to the environment variable issue. I posted this as a minimum working example because notepad.exe is common.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I highly recommend using the PIPE method as posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;.&amp;nbsp; That way your SAS program can see any messages generated by the program and/or the operating system.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 21:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Percent-Sign-in-X-Statement/m-p/678704#M204885</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-22T21:53:15Z</dc:date>
    </item>
  </channel>
</rss>

