<?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 store the return value of unix command in a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783556#M249868</link>
    <description>Thanks Carmine and Tom for useful tips , it helps to achieve the solution</description>
    <pubDate>Thu, 02 Dec 2021 07:43:55 GMT</pubDate>
    <dc:creator>learn_SAS_23</dc:creator>
    <dc:date>2021-12-02T07:43:55Z</dc:date>
    <item>
      <title>How to store the return value of unix command in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783424#M249789</link>
      <description>&lt;P&gt;Hello Team ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;am looking forward to achieve below through macro&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Scenario :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if status = 3 and run_time between (19 hrs to next day 5 hrs)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; check the whether .sas program is running in Unix or not&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and the result of Ps command stored in users home directory temp1.txt&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;x '(ps -ef | grep test_program.sas | grep -v grep)&amp;gt;/home/temp1.txt';&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;calculate the length of file and store the return value from unix in a variable through below command&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;%let file_length = x '(stat -c %s /home/temp1.txt)';&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if file_length=0 then %put the program is not executed ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else then %put the program is still running ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end if&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. how to store the current time in a variable ?&lt;/P&gt;
&lt;P&gt;2. How to store the return value of unix command in a macro variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help with your suggestions on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 17:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783424#M249789</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2021-12-01T17:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to store the return value of unix command in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783427#M249791</link>
      <description>&lt;P&gt;Do you want the text the command writes?&lt;/P&gt;
&lt;P&gt;Use the PIPE filename engine.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
  infile 'my unix command' pipe truncover;
  input line $200.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could add a CALL SYMPUTX() if you wanted the result in a macro variable instead of a real variable in a real dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 18:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783427#M249791</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-01T18:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to store the return value of unix command in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783429#M249792</link>
      <description>&lt;P&gt;So based on your example, I would highly recommend you take some SAS training course. More specifically the&amp;nbsp;SAS Macro Language 1: Essentials course(please note that the prerequisite for this course is the&amp;nbsp;SAS Programming 2: Data Manipulation Techniques).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro course is two days of training and will help you understand that you are mixing compile time statements and execution time statements in your example, which means that it will never work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to answer you First question, "getting the&amp;nbsp;&lt;SPAN&gt;result of Ps command stored in users home directory temp1.txt and storing that value in a macro" here is how i would handle this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;You can try using the data step to read the text file and use call symputx to create a macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example using the pipe command(you need to have x commands enabled for this to work on a sas server).&lt;/P&gt;
&lt;P&gt;filename filelist pipe '&lt;STRONG&gt;stat -c %s /home/temp1.txt&lt;/STRONG&gt;&amp;nbsp;';&lt;BR /&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;infile filelist truncover;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;input filename $100.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; call symputx("newMacro",filename); /*This puts the entire piped contents into the macro, i think you might&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want to use a sas function to filter this value*/&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how you would store the current time in a macro variable;&lt;/P&gt;
&lt;P&gt;%let time=%sysfunc(time(),time16.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Carmine&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 18:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783429#M249792</guid>
      <dc:creator>CarmineVerrell</dc:creator>
      <dc:date>2021-12-01T18:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to store the return value of unix command in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783556#M249868</link>
      <description>Thanks Carmine and Tom for useful tips , it helps to achieve the solution</description>
      <pubDate>Thu, 02 Dec 2021 07:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-store-the-return-value-of-unix-command-in-a-macro/m-p/783556#M249868</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2021-12-02T07:43:55Z</dc:date>
    </item>
  </channel>
</rss>

