<?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 Terminating by condition and informing about it in log in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686930#M208501</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HELLO;
%global game;
%let game = 0;
run;
%mend HELLO;
%HELLO;

data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
	retain STUDYID DOMAIN VISITNUM; 							
	set TV;

		if &amp;amp;game. ne 0 then abort cancel;
		if &amp;amp;game. ne 0 then 
		
		putlog'WARNING: A prior error has occurred or environment is not correctly initialised. WARNING: SDTME_TV_ALL_V01 terminated';

		if &amp;amp;game. eq 0 then
%do;
/*And&amp;nbsp;then&amp;nbsp;the&amp;nbsp;rest&amp;nbsp;of&amp;nbsp;the&amp;nbsp;program follows*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The task is to terminate the program without output if the global macro variable is not 0, and then write the warning in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me. Iv'e never worked with global macro variable before, or tried to write something in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;</description>
    <pubDate>Sat, 26 Sep 2020 14:45:34 GMT</pubDate>
    <dc:creator>Ninna1</dc:creator>
    <dc:date>2020-09-26T14:45:34Z</dc:date>
    <item>
      <title>Terminating by condition and informing about it in log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686930#M208501</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HELLO;
%global game;
%let game = 0;
run;
%mend HELLO;
%HELLO;

data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
	retain STUDYID DOMAIN VISITNUM; 							
	set TV;

		if &amp;amp;game. ne 0 then abort cancel;
		if &amp;amp;game. ne 0 then 
		
		putlog'WARNING: A prior error has occurred or environment is not correctly initialised. WARNING: SDTME_TV_ALL_V01 terminated';

		if &amp;amp;game. eq 0 then
%do;
/*And&amp;nbsp;then&amp;nbsp;the&amp;nbsp;rest&amp;nbsp;of&amp;nbsp;the&amp;nbsp;program follows*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The task is to terminate the program without output if the global macro variable is not 0, and then write the warning in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me. Iv'e never worked with global macro variable before, or tried to write something in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2020 14:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686930#M208501</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2020-09-26T14:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Terminating by condition and informing about it in log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686933#M208502</link>
      <description>&lt;P&gt;You have a %DO in open code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		if &amp;amp;game. eq 0 then
%do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Sep 2020 15:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686933#M208502</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-26T15:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Terminating by condition and informing about it in log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686984#M208523</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349190"&gt;@Ninna1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is quite correct.&amp;nbsp; You cannot have a %do inside of a Data step as part of the Data step logic.&amp;nbsp; I would change your code as shown below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comments:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Take the RUN out of your Hello macro.&amp;nbsp; It doesn't belong there.&lt;/LI&gt;
&lt;LI&gt;Create a little macro to abort the program if needed.&amp;nbsp; In my environment, I put this macro in an Autocall library so that all my programs can use it.&lt;/LI&gt;
&lt;LI&gt;Use a macro IF statement to check the macro variable that holds your code (&amp;amp;Game).&amp;nbsp; It's not necessary to put a Macro IF statement inside a %Macro - %Mend structure as of SAS 9.4 M5 (but you must use a %Do - %End, and you cannot nest %IF statements).&amp;nbsp; The macro %IF statement issues the warning and aborts the program before any subsequent code even starts.&amp;nbsp; The data set Out.TV cannot be affected, and your Data step doesn't have a lot of extraneous code in it.&lt;/LI&gt;
&lt;LI&gt;The %BQUOTE protects you if a non-numeric value (or no value at all) is in the macro variable &amp;amp;Game.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HELLO;
    %global game;
    %let game = 0;
%mend HELLO;
%HELLO;

%MACRO  Abort_Pgm;
    %ABORT CANCEL;
%MEND;

%IF  %BQUOTE(&amp;amp;Game) ^= 0  THEN
    %DO;
        %PUT  WARNING: A prior error has occurred or environment is not correctly initialized. ;
        %PUT  WARNING: SDTME_TV_ALL_V01 terminated';
        %Abort_Pgm;
    %END;

data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
	retain STUDYID DOMAIN VISITNUM; 							
	set TV;
/* the rest of the program follows*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sun, 27 Sep 2020 02:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/686984#M208523</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-27T02:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Terminating by condition and informing about it in log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/687166#M208592</link>
      <description>Thank you so much!</description>
      <pubDate>Mon, 28 Sep 2020 10:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/687166#M208592</guid>
      <dc:creator>Ninna1</dc:creator>
      <dc:date>2020-09-28T10:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Terminating by condition and informing about it in log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/687363#M208658</link>
      <description>&lt;P&gt;You are welcome.&amp;nbsp; Good luck with your program.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 23:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Terminating-by-condition-and-informing-about-it-in-log/m-p/687363#M208658</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-28T23:03:41Z</dc:date>
    </item>
  </channel>
</rss>

