<?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: figuring out a way to force macro to return a numeric value as output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802004#M315683</link>
    <description>&lt;P&gt;It might help to describe what the purpose is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty much can guarantee and macro that calls a data step or other procedure will not do what you want with an assignment inside a data step. As soon as the macro generated data step or proc boundary is found then the previous data step calling the macro will 1) terminate 2) likely with a syntax error because what followed the Z= was not a valid assignment:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example code would include the "statement"&lt;/P&gt;
&lt;PRE&gt;Z = filename process pipe
"powershell -File C:\Temp\gepoch.ps1 "&amp;amp;twopath."";&lt;/PRE&gt;
&lt;P&gt;which is not a valid call to the FILENAME function in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I see statements like " (for as many rows as I need to generate later), and then do my top 20 or top 30 data sets with included " one starts suspecting the problem definition needs to be revised as "generating rows" is maybe better accomplished outside of macro coding.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 17:55:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-03-14T17:55:18Z</dc:date>
    <item>
      <title>figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801991#M315674</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there is some way to do this via %SYSFUNC (or so I have heard), but I am having a very difficult time getting much to work and was wondering if anyone else here has ever encountered this same problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, all I need to do is have this macro return a numeric result, so that I can utilize it something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data s1 ;&lt;BR /&gt;date_x = 22;&lt;BR /&gt;date_y = 33;&lt;BR /&gt;date_z = %getepoch(path) ;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The point of the macro itself is simply to derive the Unix epoch time for a supplied (non-epoch'ed) date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have most of what I need already working, but I still don't think the macro is returning an assignable value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An additional problem or question might be:&amp;nbsp; is there any way to replicate the Powershell execution piece of functionality without invoking 'filename process pipe' ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that section in particular is breaking something in the SAS interpreter. I have pasted a screenshot of that at the following URL:&amp;nbsp;&amp;nbsp;&lt;A href="https://ibb.co/K9hssG3" target="_blank"&gt;output-log-d — ImgBB (ibb.co)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[actual URL plaintext =&amp;nbsp;&amp;nbsp;&lt;A href="https://ibb.co/K9hssG3" target="_blank"&gt;https://ibb.co/K9hssG3&lt;/A&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code snippet is provided below. Side note: I'm pretty sure my numeric format or bestd20 is wrong somehow (still working on that). Thanks in advance if anyone has some ideas on how to fix this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;code&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro getepoch(twopath);&lt;BR /&gt;%let twopath = %sysfunc(quote(%qsysfunc(dequote(&amp;amp;path))));&lt;BR /&gt;filename process pipe&lt;BR /&gt;"powershell -File C:\Temp\gepoch.ps1 "&amp;amp;twopath."";&lt;/P&gt;&lt;P&gt;data processes;&lt;BR /&gt;infile process ;&lt;BR /&gt;length&lt;BR /&gt;time 8;&lt;BR /&gt;format time bestd20. ;&lt;BR /&gt;input time;&lt;BR /&gt;run ; quit;&lt;BR /&gt;proc sql;&lt;BR /&gt;select time into :t2 from processes ;&lt;BR /&gt;quit;&lt;BR /&gt;%put &amp;amp;t2. ;&lt;BR /&gt;%mend getepoch;&lt;/P&gt;&lt;P&gt;%let path="C:\Temp\output9.txt" ;&lt;BR /&gt;%getepoch(path) ;&lt;/P&gt;&lt;P&gt;data s1 ;&lt;BR /&gt;x = 22;&lt;BR /&gt;y = 33;&lt;BR /&gt;z = %getepoch(path) ;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801991#M315674</guid>
      <dc:creator>m_storer_720</dc:creator>
      <dc:date>2022-03-14T17:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801993#M315676</link>
      <description>&lt;P&gt;Is macro variable &amp;amp;t2 inside macro %&lt;SPAN&gt;getepoch&amp;nbsp;&lt;/SPAN&gt;a number? Seems like an important detail which you haven't mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a number, you can add (at the top of your code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local t2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then run the macro and next in your data step&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z=&amp;amp;t2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it is not a number, then we can't help you.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801993#M315676</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-14T17:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801996#M315678</link>
      <description>Hi Paige,&lt;BR /&gt;&lt;BR /&gt;Thank you for the reply. Yes I can confirm that, in this case, &amp;amp;t2 would be a Numeric / BESTD20.&lt;BR /&gt;&lt;BR /&gt;I have used the %local variables before, but I was trying to do this in such a way that I can just dynamically call the macro anywhere in open code and be guaranteed a result.&lt;BR /&gt;&lt;BR /&gt;I think your idea *would* work - I would probably just have to declare several %local variables up front (for as many rows as I need to generate later), and then do my top 20 or top 30 data sets with included %gepoch'ed return values manually specified within the individual data steps.&lt;BR /&gt;&lt;BR /&gt;To be fair, the entire solution as I have devised it may be a bit overly complex. Forgive me if I am generating more wood chips than wood. I am still relatively new to SAS.&lt;BR /&gt;&lt;BR /&gt;Thanks again</description>
      <pubDate>Mon, 14 Mar 2022 17:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/801996#M315678</guid>
      <dc:creator>m_storer_720</dc:creator>
      <dc:date>2022-03-14T17:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802001#M315681</link>
      <description>Can we assume that you've already confirmed there's no way to accomplish this within SAS already?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;The point of the macro itself is simply to derive the Unix epoch time for a supplied (non-epoch'ed) date.</description>
      <pubDate>Mon, 14 Mar 2022 17:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802001#M315681</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-14T17:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802002#M315682</link>
      <description>&lt;P&gt;TYPO&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I should have used %GLOBAL and not %LOCAL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I have used the %local variables before, but I was trying to do this in such a way that I can just dynamically call the macro anywhere in open code and be guaranteed a result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Again, I should have said %GLOBAL, and then you can do exactly what you just said, your value of &amp;amp;t2 can be used anywhere.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802002#M315682</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-14T17:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802004#M315683</link>
      <description>&lt;P&gt;It might help to describe what the purpose is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty much can guarantee and macro that calls a data step or other procedure will not do what you want with an assignment inside a data step. As soon as the macro generated data step or proc boundary is found then the previous data step calling the macro will 1) terminate 2) likely with a syntax error because what followed the Z= was not a valid assignment:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example code would include the "statement"&lt;/P&gt;
&lt;PRE&gt;Z = filename process pipe
"powershell -File C:\Temp\gepoch.ps1 "&amp;amp;twopath."";&lt;/PRE&gt;
&lt;P&gt;which is not a valid call to the FILENAME function in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I see statements like " (for as many rows as I need to generate later), and then do my top 20 or top 30 data sets with included " one starts suspecting the problem definition needs to be revised as "generating rows" is maybe better accomplished outside of macro coding.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802004#M315683</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-14T17:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802006#M315684</link>
      <description>&lt;P&gt;How about wrapping 4GL in a %sysfunc(DoSubL(...)) sandwich?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getepoch(path);
%local t2;
%LET RC = %SYSFUNC(DOSUBL(%STR( /* &amp;lt;- sandwich start */
filename process pipe
"powershell -File C:\Temp\gepoch.ps1 ""&amp;amp;path.""";
data processes;
infile process ;
length
time 8;
format time bestd20. ;
input time;
run ; quit;
proc sql;
select time into :t2 from processes ;
quit;
))); /* &amp;lt;- sandwich end */
&amp;amp;t2.
%mend getepoch;

%let path=C:\Temp\output9.txt ;
%getepoch(&amp;amp;path.) ;

data s1 ;
x = 22;
y = 33;
z = %getepoch(&amp;amp;path.) ;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802006#M315684</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-14T17:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802020#M315687</link>
      <description>&lt;P&gt;I did not realize that DOSUBL would work like this inside of a macro. So now I have caught up to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;, I have learned a new thing today: a new use case for DOSUBL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is still quite a lot of arcane programming just to make &amp;amp;t2 available outside of the the macro, which is "less arcane" programming. But the idea of calling the macro wherever the user wants to call it, such as within a data step, still bothers me when you could just use &amp;amp;t2 in that data step. However, if that's what the OP wants...&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 18:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802020#M315687</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-14T18:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802029#M315691</link>
      <description>&lt;A href="https://blogs.sas.com/content/sasdummy/2015/04/16/how-to-convert-a-unix-datetime-to-a-sas-datetime/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/04/16/how-to-convert-a-unix-datetime-to-a-sas-datetime/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/EPOCH-Time-conversion/td-p/104154" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/EPOCH-Time-conversion/td-p/104154&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I would guess that if you can go in one direction you can go in the other.</description>
      <pubDate>Mon, 14 Mar 2022 18:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802029#M315691</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-14T18:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802033#M315695</link>
      <description>Hello Reeza,&lt;BR /&gt;&lt;BR /&gt;good question with respect to eliminating the possibility of not being able to just do this in straight SAS.&lt;BR /&gt;&lt;BR /&gt;The initial need for me to write the Powershell wrapper for epoch'ed times was to devise some kind of a workaround to the classic Windows DST time and datestamps on files issue.&lt;BR /&gt;&lt;BR /&gt;So I guess the genesis of this whole thing comes from having to bootstrap some way to interrogate a given Windows filesystem as to exactly what the time was on a file / was it DST'ed or No / and then proceed onward to the next function of a larger, proper SAS DI job.&lt;BR /&gt;&lt;BR /&gt;Of course, we have a couple different SAS jobs that pull file metadata in from Windows but the root problem was that Windows, as an OS does not always accurately self report.</description>
      <pubDate>Mon, 14 Mar 2022 18:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802033#M315695</guid>
      <dc:creator>m_storer_720</dc:creator>
      <dc:date>2022-03-14T18:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: figuring out a way to force macro to return a numeric value as output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802036#M315697</link>
      <description>&lt;P&gt;Yabwon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help. This is a really clever solution, and it seems to test just fine on my system.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 18:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/figuring-out-a-way-to-force-macro-to-return-a-numeric-value-as/m-p/802036#M315697</guid>
      <dc:creator>m_storer_720</dc:creator>
      <dc:date>2022-03-14T18:33:46Z</dc:date>
    </item>
  </channel>
</rss>

