<?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 return a value inside a MACRO when it failed in middle?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833469#M329483</link>
    <description>&lt;P&gt;For static file, it is. The macro reads in perfectly, but I need read it in real time in which the file is being written by C++.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 01:30:28 GMT</pubDate>
    <dc:creator>hellohere</dc:creator>
    <dc:date>2022-09-15T01:30:28Z</dc:date>
    <item>
      <title>How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833282#M329398</link>
      <description>&lt;P&gt;Here is a way to return a value inside a MACRO.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But how to return a specific value, say -1, when the macro failed in middle?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My macro simply reads a delimited file into a dataset in an automatic process; somehow it fails occasionally. I need know whether failed or not&lt;/P&gt;
&lt;P&gt;and plan to re-read it seconds later if failed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 07:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833282#M329398</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-14T07:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833292#M329402</link>
      <description>&lt;P&gt;So what is the failure? Data set not created? Zero obs in data set? Character variables where it should be numeric? Something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/p0f7j2zr6z71nqn1fpefnmulzazf.htm" target="_self"&gt;%ABORT CANCEL -1;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 09:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833292#M329402</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-14T09:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833306#M329408</link>
      <description>&lt;P&gt;Please share your macro, and describe how it fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For general approaches to exception handling in SAS, see lots of papers and books by Troy Hughes, e.g.:&amp;nbsp;&lt;A href="https://www.lexjansen.com/search/searchresults.php?q=troy%20hughes" target="_blank"&gt;https://www.lexjansen.com/search/searchresults.php?q=troy%20hughes&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 11:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833306#M329408</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-14T11:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833314#M329411</link>
      <description>&lt;P&gt;The best way to return a value from a macro call is via a macro variable.&amp;nbsp; You need to make sure the macro variable exists in the calling environment (or the GLOBAL environment).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(parm1,parm2,mvarname);
%if not %symexist(&amp;amp;mvarname) %then %global &amp;amp;mvarname;
....
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then after you call the macro you can test the value of the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mymacro(parm1=sashelp.class,parm2=name,mvarname=status);
%if &amp;amp;status=1 %then %put It worked;
%else %put it failed;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2022 11:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833314#M329411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-14T11:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833355#M329421</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here is a way to return a value inside a MACRO.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But how to return a specific value, say -1, when the macro failed in middle?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My macro simply reads a delimited file into a dataset in an automatic process; somehow it fails occasionally. I need know whether failed or not&lt;/P&gt;
&lt;P&gt;and plan to re-read it seconds later if failed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why does the read of a delimited file "fail"? Some concrete example might be in order. Fix the desired process instead of the error messaging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My experience with "failed" reading of delimited data files always comes down to the accuracy of the description of the delimited file. Either someone changes the content of the file or one or more fields were not properly described and changing content brings out the flaw in the description.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 15:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833355#M329421</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-14T15:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833468#M329482</link>
      <description>&lt;P&gt;Let me get the log later since it does not happen every time. The Macro only has Proc IMPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that the to-read-in file is being written in real time by C++.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro readin(dt, pt);
	/*%let dt=0606; %let pt=10;*/
	PROC IMPORT OUT=pgap_p&amp;amp;pt.
	     DATAFILE="C:\Users\Administrator\Desktop\data\1min__2022&amp;amp;dt._&amp;amp;pt..log"
	   DBMS=CSV REPLACE;
	   GETNAMES=NO;
	   DATAROW=1;
	RUN;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 01:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833468#M329482</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-15T01:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833469#M329483</link>
      <description>&lt;P&gt;For static file, it is. The macro reads in perfectly, but I need read it in real time in which the file is being written by C++.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 01:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833469#M329483</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-15T01:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833481#M329487</link>
      <description>&lt;P&gt;So the question is no longer how to return something from a macro execution.&lt;/P&gt;
&lt;P&gt;Now the question is how to tell when a step fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are using PROC IMPORT that already creates a macro variable as part of the SAS code it generates.&amp;nbsp; Check the SAS log for one your runs (with MPRINT option on of course) to see the macro variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you might be able to use that macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro readin(dt, pt);
PROC IMPORT OUT=pgap_p&amp;amp;pt.
     DATAFILE="C:\Users\Administrator\Desktop\data\1min__2022&amp;amp;dt._&amp;amp;pt..log"
     DBMS=CSV REPLACE
;
   GETNAMES=NO;
   DATAROW=1;
RUN;
%mend;

%* Give the macro variable a value so it exists outside the macro scope ;
%let _EFIERR_= Before macro call;
%* Call the macro ;
%readin(dt=0606,pt=10)
%* Test the value of the macro variable ;
%put &amp;amp;=_EFIERR_ ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could just test if the dataset is created or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(exist(pgap_p10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;nbsp; &amp;nbsp; Why would you use PROC IMPORT?&amp;nbsp; Especially if the file does not have a header row.&amp;nbsp; Does the structure of the file change?&amp;nbsp; Why do you need to use a guessing program to read it?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 04:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833481#M329487</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-15T04:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a value inside a MACRO when it failed in middle?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833756#M329611</link>
      <description>&lt;P&gt;Create a macro before and after Proc IMPORT would be a good try, I BET.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check the dataset is created or not is not, since I need read the same file with same output dataset periodically.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 02:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-return-a-value-inside-a-MACRO-when-it-failed-in-middle/m-p/833756#M329611</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-16T02:07:04Z</dc:date>
    </item>
  </channel>
</rss>

