<?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: pass SAS variable value to call system and write result within a datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703434#M215532</link>
    <description>&lt;P&gt;Use a dynamic pipe:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data users;
input username $;
datalines;
sasbatch
;

data uids;
set users;
fvar = catx(" ","id -u",username,'2&amp;gt;&amp;amp;1');
infile dummy pipe filevar=fvar end=done;
do until (done);
  input id;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Dec 2020 16:36:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-03T16:36:54Z</dc:date>
    <item>
      <title>pass SAS variable value to call system and write result within a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703426#M215526</link>
      <description>&lt;P&gt;I need a system lookup to get the uid of a Unix userid. Using macro variables, this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let userid = sasbatch ;&lt;/P&gt;
&lt;P&gt;filename tmp pipe "id -u &amp;amp;userid" ;&lt;BR /&gt;data _null_ ;&lt;BR /&gt;infile tmp ;&lt;BR /&gt;input uid ;&lt;BR /&gt;put uid= ;&lt;BR /&gt;call symput('uid',uid) ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;=uid ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 data steps needed without macro variables :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_ ;&lt;BR /&gt;userid = 'sasbatch' ;&lt;BR /&gt;command = cat('id -u ',userid, ' &amp;gt; /tmp/uid_out.txt' ) ;&lt;BR /&gt;put command= ; /* id -u sasbatch &amp;gt; /tmp/uid_out.txt as expected */&lt;BR /&gt;call system(command) ;&lt;BR /&gt;%put %sysfunc(sysrc()) - %sysfunc(sysmsg()) ; /* Nothing useful */&lt;BR /&gt;/* Cannot be opened within the same step&lt;BR /&gt;filename tmpin '/tmp/uid_out.txt' ;&lt;BR /&gt;infile tmpin ;&lt;BR /&gt;input uid ;&lt;BR /&gt;put uid= ;&lt;BR /&gt;*/&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_ ;&lt;BR /&gt;filename tmpin '/tmp/uid_out.txt' ;&lt;BR /&gt;infile tmpin ;&lt;BR /&gt;input uid ;&lt;BR /&gt;put uid= ; /* 506 as expected */&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a single data step solution?&lt;/P&gt;
&lt;P&gt;Without '&amp;gt; /tmp/uid_out.txt' , the result 506 is displayed in the calling Unix shell as standard output. Is there anyway to read it back in ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 15:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703426#M215526</guid>
      <dc:creator>acfarrer</dc:creator>
      <dc:date>2020-12-03T15:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: pass SAS variable value to call system and write result within a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703434#M215532</link>
      <description>&lt;P&gt;Use a dynamic pipe:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data users;
input username $;
datalines;
sasbatch
;

data uids;
set users;
fvar = catx(" ","id -u",username,'2&amp;gt;&amp;amp;1');
infile dummy pipe filevar=fvar end=done;
do until (done);
  input id;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Dec 2020 16:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703434#M215532</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-03T16:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: pass SAS variable value to call system and write result within a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703466#M215551</link>
      <description>Awesome and quick ! &lt;BR /&gt;I had tried filename pipe but not tried to read the output. Using filevar= for username is very creative . &lt;BR /&gt;Thanks very much - I am sure others will find it useful</description>
      <pubDate>Thu, 03 Dec 2020 18:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703466#M215551</guid>
      <dc:creator>acfarrer</dc:creator>
      <dc:date>2020-12-03T18:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: pass SAS variable value to call system and write result within a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703469#M215552</link>
      <description>&lt;P&gt;I call this thing the "dynamic pipe". Hopefully, it will be part of a presentation at SAS Global Forum 2022 in San Diego.&lt;/P&gt;
&lt;P&gt;You will have noticed the "2&amp;gt;&amp;amp;1" I added to the external command. It instructs the system to reroute stderr (error output) to stdout (the standard output stream), so that SAS catches it. You can use extra logic to detect anything abnormal in the response, by looking for unexpected strings/characters in _INFILE_.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 18:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pass-SAS-variable-value-to-call-system-and-write-result-within-a/m-p/703469#M215552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-03T18:48:59Z</dc:date>
    </item>
  </channel>
</rss>

