<?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: if then loop within data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407758#M99376</link>
    <description>&lt;P&gt;When debugging programs with macro-variables always turn on options mprint and symbolgen. Posting the log will make debugging easier, because without your data we are unable to reproduce the problem you have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is an error in your first data-step, you can't use&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;var1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;without having var1 in the BY-statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The if-then-statement is not a loop &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2017 18:00:10 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2017-10-26T18:00:10Z</dc:date>
    <item>
      <title>if then loop within data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407745#M99370</link>
      <description>&lt;P&gt;The following code works as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	set have;
	by veh_no;

	if veh_no="&amp;amp;num" then
		do;
			if var1 ne '0' then
				do;
					if first.var1 then
						cusumvar1=0;
					cusumvar1+1;
				end;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I add a similar if then loop I get an error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: (, +, =.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	set have;
	by veh_no;

	if veh_no="&amp;amp;num" then
		do;
			if var1 ne '0' then
				do;
					if first.var1 then
						cusumvar1=0;
					cusumvar1+1;
				end;

			if var2 ne '0' then
				do;
					if first.var2 then
						cusumvar2=0;
					cusumvar2+1;
				end;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Oct 2017 17:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407745#M99370</guid>
      <dc:creator>capam</dc:creator>
      <dc:date>2017-10-26T17:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: if then loop within data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407755#M99375</link>
      <description>&lt;P&gt;A few notes might help push you in the right direction ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, don't use DATA HAVE; SET HAVE; when you are experimenting and trying to get a program to work.&amp;nbsp; If an experiment fails (but doesn't generate an error message), you will have replaced your data with a poor substitute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, either you didn't show the code you ran, or your expectations are bizarre.&amp;nbsp; There is no way the top program ran "as expected" when you include this combination of statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BY VEH_NO;&lt;/P&gt;
&lt;P&gt;IF FIRST.VAR1 THEN ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program doesn't create FIRST.VAR1.&amp;nbsp; At a minimum, the log should give you a message to that effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, is this code part of a macro?&amp;nbsp; If not, you should be able to pinpoint in the log which statement the error message refers to.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 17:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407755#M99375</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-26T17:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: if then loop within data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407758#M99376</link>
      <description>&lt;P&gt;When debugging programs with macro-variables always turn on options mprint and symbolgen. Posting the log will make debugging easier, because without your data we are unable to reproduce the problem you have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is an error in your first data-step, you can't use&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;var1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;without having var1 in the BY-statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The if-then-statement is not a loop &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-loop-within-data/m-p/407758#M99376</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-10-26T18:00:10Z</dc:date>
    </item>
  </channel>
</rss>

