<?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 Syntax error with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657621#M197090</link>
    <description>&lt;P&gt;Can i get help with this SAS steps I wrote. I am new to SAS and I cannot figure out why I am having errors in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MSM_IDU;&lt;BR /&gt;set testing_data ;&lt;BR /&gt;format risk $10.;&lt;BR /&gt;if x742 ne '1' then risk='UNKNOWN';&lt;BR /&gt;else if g124 in ('1' '3') then do;&lt;BR /&gt;if g216a='1' then do;&lt;BR /&gt;if g402='1' then risk='MSM/IDU';&lt;BR /&gt;else risk='MSM';&lt;BR /&gt;end;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jun 2020 17:31:35 GMT</pubDate>
    <dc:creator>adzoyi</dc:creator>
    <dc:date>2020-06-11T17:31:35Z</dc:date>
    <item>
      <title>Syntax error with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657621#M197090</link>
      <description>&lt;P&gt;Can i get help with this SAS steps I wrote. I am new to SAS and I cannot figure out why I am having errors in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MSM_IDU;&lt;BR /&gt;set testing_data ;&lt;BR /&gt;format risk $10.;&lt;BR /&gt;if x742 ne '1' then risk='UNKNOWN';&lt;BR /&gt;else if g124 in ('1' '3') then do;&lt;BR /&gt;if g216a='1' then do;&lt;BR /&gt;if g402='1' then risk='MSM/IDU';&lt;BR /&gt;else risk='MSM';&lt;BR /&gt;end;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657621#M197090</guid>
      <dc:creator>adzoyi</dc:creator>
      <dc:date>2020-06-11T17:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657623#M197092</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303797"&gt;@adzoyi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's hard to say without some data to play with.&lt;/P&gt;
&lt;P&gt;It seems that an 'end' statement is missing at the end of the program to close the Do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MSM_IDU;
	set testing_data;
	format risk $10.;

	if x742 ne '1' then risk='UNKNOWN';
	else if g124 in ('1' '3') then
		do;
			if g216a='1' then
				do;
					if g402='1' then
						risk='MSM/IDU';
					else
						risk='MSM';
				end;
		end; /* &amp;lt;&amp;lt;-- to be added*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tip: to facilitate the identification of syntax error, do not hesitate to format your code and use proper indentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657623#M197092</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-11T17:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657638#M197103</link>
      <description>&lt;P&gt;When you get an error best practice for this forum is to copy from the Log the data step or Proc code along with all the messages. The Paste into a code box opened with the &amp;lt;/&amp;gt; icon to preserve formatting. The main message windows will reformat text so the diagnostic characters that SAS often supplies do not appear in the correct place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example:&lt;/P&gt;
&lt;PRE&gt;190  data junk;
191     set sashelp.class;
192     if sex='F' then do;
193        junk=age*weight;
194  run;

194  run;
        -
        117
ERROR 117-185: There was 1 unclosed DO block.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JUNK may be incomplete.  When this step was stopped there were 0
         observations and 6 variables.
WARNING: Data set WORK.JUNK was not replaced because this step was stopped.

&lt;/PRE&gt;
&lt;P&gt;The message is moderately clear: there was Do statement without a matching End to close the Do block.&lt;/P&gt;
&lt;P&gt;The diagnostic characters appear with the Run statement in this case as it ends the data step and is the first thing SAS can indicate as "not an end statement".&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657638#M197103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-11T17:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657646#M197109</link>
      <description>&lt;P&gt;missing comma in the IN stmt and a missing end&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;else if g124 in ('1' , '3') then&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* full code;
data MSM_IDU;
set testing_data ;
format risk $10.;
if x742 ne '1' then risk='UNKNOWN';
else if g124 in ('1', '3') then do;
if g216a='1' then do;
if g402='1' then risk='MSM/IDU';
else risk='MSM';
end;
end;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 18:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657646#M197109</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-06-11T18:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657649#M197110</link>
      <description>&lt;P&gt;Looks like other community members beat me to the punch.&lt;BR /&gt;I'd like to add it's a good idea to format/indent your code which makes it easier to debug&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MSM_IDU;
	set testing_data ;
	format risk $10.;
	if x742 ne '1' then 
		risk='UNKNOWN';
	else 
	if g124 in ('1', /* &amp;lt;-- NEED THIS COMMA HERE */ '3') then do;
		if g216a='1' then do;
			if g402='1' then risk='MSM/IDU';
			else risk='MSM';
		end;
	end ; /* &amp;lt;-- NEED THIS EXTRA END */
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 18:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-with-do-loop/m-p/657649#M197110</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-06-11T18:40:53Z</dc:date>
    </item>
  </channel>
</rss>

