<?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 pass the results of X commands to variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516984#M139677</link>
    <description>&lt;P&gt;I would not use an X command or pipe for that. SAS has very good functions for directories. One possibility is to use them in to create a macro function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dnum(path);
  %local fileref rc did memcount;
  /* Fileref is empty, so we assign a temporary, unique fileref */
  %let rc=%sysfunc(filename(fileref, &amp;amp;path));
  %let did=%sysfunc(dopen(&amp;amp;fileref));
  %let memcount=%sysfunc(dnum(&amp;amp;did));
  /* Close directory handle */
  %let rc=%sysfunc(dclose(&amp;amp;did));
  /* deassign fileref */
  %let fileref=%sysfunc(filename(fileref));
&amp;amp;memcount
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then you can just use that macro function to get the number of entries in each directory, like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file outbox &amp;lt;email options&amp;gt;; /* this is the email fileref */
  if %dnum(/home/unix/dir/one)=%dnum(/home/unix/dir/two) then do;
    call system('sas runsasprog.sas');
    put '!EM_ABORT!'; /* Don't send no email */
    end;
  else … /* write something in the email message */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Nov 2018 10:17:56 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-11-29T10:17:56Z</dc:date>
    <item>
      <title>How to pass the results of X commands to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516860#M139633</link>
      <description>&lt;P&gt;I need some code examples. I am trying to pass the values of a couple of X commands to variables and then use the two values in a if-then/do. I've provided some pseudo code to help explain what I'm trying to accomplish. Thanks.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'cd /home/unix/dir/one';
x 'ls -1 | wc -l';

x 'cd /home/unix/dir/two';
x 'ls -1 | wc -l';

if results of first piped command = results of second piped command
then do;
x 'sas runsasprog.sas';
end;
else send email;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 20:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516860#M139633</guid>
      <dc:creator>ijmoorejr</dc:creator>
      <dc:date>2018-11-28T20:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the results of X commands to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516875#M139637</link>
      <description>&lt;P&gt;Look in the documentation for FILENAME PIPE and examples to create data sets of the results. Then compare the contents of the datasets. Since I am not sure what you might be considering for "equality" between the output of the commands since creation and or modification datetimes are very likely to be different I am not going to attempt the comparison.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 21:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516875#M139637</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-28T21:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the results of X commands to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516879#M139640</link>
      <description>&lt;P&gt;The command 'ls -1 | wc -l' returns the number of files in a given directory. It will simply return a number without timestamps or anything like that. The object is to compare the number/count of files of one directory to another.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 21:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516879#M139640</guid>
      <dc:creator>ijmoorejr</dc:creator>
      <dc:date>2018-11-28T21:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the results of X commands to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516882#M139641</link>
      <description>&lt;P&gt;Don't use X command. Use PIPE engine instead.&lt;/P&gt;
&lt;P&gt;So read the two numbers into two variables and compare number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could for example put the result into a macro variable that you could use to drive what to do next.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   infile 
'cd /home/unix/dir/one
;ls -1 | wc -l
;cd /home/unix/dir/two
;ls -1 | wc -l
' pipe truncover;
  input x y ;
  call symputx('match',x=y);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 21:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516882#M139641</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-28T21:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the results of X commands to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516984#M139677</link>
      <description>&lt;P&gt;I would not use an X command or pipe for that. SAS has very good functions for directories. One possibility is to use them in to create a macro function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dnum(path);
  %local fileref rc did memcount;
  /* Fileref is empty, so we assign a temporary, unique fileref */
  %let rc=%sysfunc(filename(fileref, &amp;amp;path));
  %let did=%sysfunc(dopen(&amp;amp;fileref));
  %let memcount=%sysfunc(dnum(&amp;amp;did));
  /* Close directory handle */
  %let rc=%sysfunc(dclose(&amp;amp;did));
  /* deassign fileref */
  %let fileref=%sysfunc(filename(fileref));
&amp;amp;memcount
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then you can just use that macro function to get the number of entries in each directory, like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file outbox &amp;lt;email options&amp;gt;; /* this is the email fileref */
  if %dnum(/home/unix/dir/one)=%dnum(/home/unix/dir/two) then do;
    call system('sas runsasprog.sas');
    put '!EM_ABORT!'; /* Don't send no email */
    end;
  else … /* write something in the email message */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 10:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-results-of-X-commands-to-variables/m-p/516984#M139677</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-11-29T10:17:56Z</dc:date>
    </item>
  </channel>
</rss>

