<?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: %goto not working as intended. Overwriting dataset or ignoring syntax in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906392#M357899</link>
    <description>&lt;P&gt;Instead of using %GOTO, wrap the two blocks in mutually exclusive %DO-%END:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro link;
%do i = 1 %to 9;
  %if &amp;amp;i ne 5 and &amp;amp;i ne 6
  %then %do;
    proc sql noprint; 
    create table link_dth&amp;amp;i as
      select  a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i,
       b.SEQ as SEQ, b.year as PMP_YEAR
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i
    ;
    quit;
  %end;
  %else %do;
    proc sql noprint; /*Link PMP with SPARCS 5,6*/
    create table link_dth&amp;amp;i as
      select a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, a.gender_DTH as DTH_GENDER,
      b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i, b.SEQ as SEQ,
      b.year as PMP_YEAR, b.gender_PMP as PMP_GENDER
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i and a.gender_DTH=b.gender_PMP
    ;
    quit;
  %end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Dec 2023 06:58:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-12-06T06:58:54Z</dc:date>
    <item>
      <title>%goto not working as intended. Overwriting dataset or ignoring syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906375#M357893</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to write a code to skip a block of syntax if i=5 or 6 in a do loop but I find that it is not working as intended. Only the %skip label ends up running and either overwrites the datasets from the first block of code or perhaps the first block of code is getting ignored for some reason. Anyone have tips for troubleshooting? Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro link;&lt;BR /&gt;%do i=1 %to 9;&lt;BR /&gt;%if &amp;amp;i=5 or &amp;amp;i=6 %then %goto skip;&lt;BR /&gt;proc sql noprint;&amp;nbsp;&lt;BR /&gt;create table link_dth&amp;amp;i as&lt;BR /&gt;select&amp;nbsp; a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i,&lt;BR /&gt;b.SEQ as SEQ, b.year as PMP_YEAR&lt;BR /&gt;from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b&lt;BR /&gt;where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%skip:&lt;BR /&gt;proc sql noprint; /*Link PMP with SPARCS 5,6*/&lt;BR /&gt;create table link_dth&amp;amp;i as&lt;BR /&gt;select a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, a.gender_DTH as DTH_GENDER,&lt;BR /&gt;b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i, b.SEQ as SEQ,&lt;BR /&gt;b.year as PMP_YEAR, b.gender_PMP as PMP_GENDER&lt;BR /&gt;from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b&lt;BR /&gt;where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i and a.gender_DTH=b.gender_PMP;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 03:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906375#M357893</guid>
      <dc:creator>Vivy1</dc:creator>
      <dc:date>2023-12-06T03:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: %goto not working as intended. Overwriting dataset or ignoring syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906390#M357898</link>
      <description>&lt;P&gt;Goto branches the program to that point. If you&amp;nbsp; do not control entrance to that branch for other values then that code executes as you found out. So you need a second %goto to branch past the other code you do not want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro link;
   %do i=1 %to 9;
      %if &amp;amp;i=5 or &amp;amp;i=6 %then %goto skip;
      proc sql noprint; 
      create table link_dth&amp;amp;i as
      select  a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i,
      b.SEQ as SEQ, b.year as PMP_YEAR
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i;
      quit;
      &lt;FONT color="#800080"&gt;&lt;STRONG&gt;%goto theend;&lt;/STRONG&gt;&lt;/FONT&gt;

      %skip:
      proc sql noprint; /*Link PMP with SPARCS 5,6*/
      create table link_dth&amp;amp;i as
      select a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, a.gender_DTH as DTH_GENDER,
      b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i, b.SEQ as SEQ,
      b.year as PMP_YEAR, b.gender_PMP as PMP_GENDER
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i and a.gender_DTH=b.gender_PMP;
      quit;

     &lt;FONT color="#800080"&gt;&lt;STRONG&gt; %theend;&lt;/STRONG&gt; &lt;/FONT&gt;
   %end;
%mend;&lt;/PRE&gt;
&lt;P&gt;Please post code and log entries in a text box opened on the forum using the &amp;lt;/&amp;gt; icon that appears above the message box to preserve formatting. Also when the code or log is in such a box it is visually separated from the question/discussion text. If you want some code highlighting you can also post code into a code box opened with the "running man" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 06:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906390#M357898</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-06T06:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: %goto not working as intended. Overwriting dataset or ignoring syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906392#M357899</link>
      <description>&lt;P&gt;Instead of using %GOTO, wrap the two blocks in mutually exclusive %DO-%END:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro link;
%do i = 1 %to 9;
  %if &amp;amp;i ne 5 and &amp;amp;i ne 6
  %then %do;
    proc sql noprint; 
    create table link_dth&amp;amp;i as
      select  a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i,
       b.SEQ as SEQ, b.year as PMP_YEAR
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i
    ;
    quit;
  %end;
  %else %do;
    proc sql noprint; /*Link PMP with SPARCS 5,6*/
    create table link_dth&amp;amp;i as
      select a.DTHID&amp;amp;i, a.year as DTH_YEAR, a.UID4S&amp;amp;i as DTH_UID4S&amp;amp;i, a.gender_DTH as DTH_GENDER,
      b.UID4S&amp;amp;i as PMP_UID4S&amp;amp;i, b.SEQ as SEQ,
      b.year as PMP_YEAR, b.gender_PMP as PMP_GENDER
      from in.cleanall_test_UID4S&amp;amp;i as a, pmp.cleanall_test_UID4S&amp;amp;i as b
      where a.UID4S&amp;amp;i=b.UID4S&amp;amp;i and a.gender_DTH=b.gender_PMP
    ;
    quit;
  %end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 06:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/goto-not-working-as-intended-Overwriting-dataset-or-ignoring/m-p/906392#M357899</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-06T06:58:54Z</dc:date>
    </item>
  </channel>
</rss>

