<?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 condition in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749382#M235472</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks much. How can i remediate the situation ? i am getting confused how if actually processes in SAS . because in the other programmer it worked perfectly.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show us the code you ran in the "other programmer", and tell us which it is, so we can explain the syntax differences.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 21:09:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-21T21:09:27Z</dc:date>
    <item>
      <title>If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749355#M235454</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then  ;&lt;BR /&gt;a = qtr_yr+1;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;I wanted to know the conditional processing of IF in the above code the if qtr_yr = 3 is not working properly as I am getting values for "a"&amp;nbsp; for other values of&amp;nbsp;qtr_yr , including&amp;nbsp; where&amp;nbsp;&amp;nbsp;qtr_yr = 3 . On the other hand , in the below code :-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting values for&amp;nbsp;qtr_yr = 3 only .&lt;/P&gt;
&lt;P&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then output ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 18:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749355#M235454</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-21T18:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749356#M235455</link>
      <description>&lt;P&gt;In your first program the IF statement is doing nothing because you have no statement between the THEN keyword and the semi-colon that marks the end of the IF statement and no ELSE statement.&amp;nbsp; So when the condition is true it does nothing and when it is false it does nothing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it you are actually trying to do?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749356#M235455</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-21T19:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749358#M235457</link>
      <description>i missed some thing the code is like this :&lt;BR /&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then a = qtr_yr + 1 ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;i want to  create variable a which will be equal to 4 , as i want output only when the qtr_yr = 3 &lt;BR /&gt;but it is not working &lt;BR /&gt;and when i try the second program &lt;BR /&gt;&lt;BR /&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then output ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;i am getting all values where  qtr_yr = 3 &lt;BR /&gt;&lt;BR /&gt;I wanted to know why the if condition is not working in program one.&lt;BR /&gt;Thanks!!</description>
      <pubDate>Mon, 21 Jun 2021 19:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749358#M235457</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-21T19:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749359#M235458</link>
      <description>&lt;P&gt;Sounds like you may want&lt;/P&gt;
&lt;PRE&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then a = qtr_yr+1;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;The ; in SAS code ends a statement. So your code was unconditionally executing the assignment of A because you ended the If clause too soon. &lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749359#M235458</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-21T19:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749361#M235460</link>
      <description>Thanks much. How can i remediate the situation ? i am getting confused how if actually processes in SAS . because in  the other programmer it worked perfectly. &lt;BR /&gt;&lt;BR /&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then output ;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 21 Jun 2021 19:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749361#M235460</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-21T19:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749363#M235462</link>
      <description>Your IF statements don't have the right syntax for the logic you want. &lt;BR /&gt;&lt;BR /&gt;IF &amp;lt;condition&amp;gt; THEN &amp;lt;action&amp;gt;;&lt;BR /&gt;&lt;BR /&gt;You have a condition in your IF statement but no action specified. &lt;BR /&gt;&lt;BR /&gt;Another format of the IF statement is the IF/THEN/DO:&lt;BR /&gt;&lt;BR /&gt;IF &amp;lt;condition&amp;gt; THEN DO;&lt;BR /&gt;&amp;lt;actions&amp;gt;&lt;BR /&gt;END;&lt;BR /&gt;&lt;BR /&gt;And the other is the IF/THEN/ELSE which isn't relevant to this question but you'll likely want to understand how it works as well.&lt;BR /&gt;&lt;BR /&gt;Subsetting IF documentation.&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;IF/THEN documentation&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1j60arf27ll4nn1ejavv3nby4pa.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1j60arf27ll4nn1ejavv3nby4pa.htm&lt;/A&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749363#M235462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-21T19:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749367#M235465</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks much. How can i remediate the situation ? i am getting confused how if actually processes in SAS . because in the other programmer it worked perfectly. &lt;BR /&gt;&lt;BR /&gt;data three;&lt;BR /&gt;set two;&lt;BR /&gt;by qtr_yr yr;&lt;BR /&gt;if qtr_yr = 3 then output ;&lt;BR /&gt;run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that in this code you actually have some action taken after the "then". The assignment code did not and I showed how to "remediate" if the goal was to assign values to the variable A only when that condition is met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the actual problem is more complex you need to provide actual examples of the values involved and ALL the rules for assignment of values to variable A (or other variable names).&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749367#M235465</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-21T19:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749379#M235470</link>
      <description>&lt;P&gt;Sounds like you want to perform BOTH actions in one step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data three;
  set two;
  if qtr_yr = 3 then a = qtr_yr + 1 ;
  if qtr_yr = 3 then output ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a DO/END block to test only once.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data three;
  set two;
  if qtr_yr = 3 then do;
    a = qtr_yr + 1 ;
    output ;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could use a subsetting IF instead of and IF/THEN statement.&lt;/P&gt;
&lt;P&gt;Notice that a subsetting IF does not use the THEN keyword.&amp;nbsp; You also do not need an explicit OUTPUT statement since only the observations where QTR_YR=3 will make it past the subsetting IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data three;
  set two;
  if qtr_yr = 3 ;
  a = qtr_yr + 1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the BY statement is doing nothing so I removed it.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 20:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749379#M235470</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-21T20:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749382#M235472</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks much. How can i remediate the situation ? i am getting confused how if actually processes in SAS . because in the other programmer it worked perfectly.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show us the code you ran in the "other programmer", and tell us which it is, so we can explain the syntax differences.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 21:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749382#M235472</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-21T21:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749466#M235507</link>
      <description>&lt;P&gt;The code you posted contains a typo, you need to remove the semi-colon after "then"&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 10:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749466#M235507</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-06-22T10:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749602#M235591</link>
      <description>Thanks! I cant paste the actual data but this is sample data &lt;BR /&gt; AccNbr  StartDate Amt ;&lt;BR /&gt;130 06Jan1999 10 &lt;BR /&gt;120 06Aug1999 10 &lt;BR /&gt;130 01Jan1990 10 &lt;BR /&gt;120 29Mar2005 11 &lt;BR /&gt;110 01Jan1990 11 &lt;BR /&gt;100 06Dec1999 11 &lt;BR /&gt;120 02Apr2013 11 &lt;BR /&gt;110 01May2003 11 &lt;BR /&gt;130 01Jul2000 11 &lt;BR /&gt;&lt;BR /&gt;I want to get output as for a particular year , particular quarter , sum of total amt.&lt;BR /&gt;e.g for year 1999 o/p should be &lt;BR /&gt;year   id  quater  sum &lt;BR /&gt;1999 130  1        20&lt;BR /&gt;1999  100 4   11  &lt;BR /&gt;&lt;BR /&gt;and so on &lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749602#M235591</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-22T15:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749613#M235597</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks! I cant paste the actual data but this is sample data &lt;BR /&gt;AccNbr StartDate Amt ;&lt;BR /&gt;130 06Jan1999 10 &lt;BR /&gt;120 06Aug1999 10 &lt;BR /&gt;130 01Jan1990 10 &lt;BR /&gt;120 29Mar2005 11 &lt;BR /&gt;110 01Jan1990 11 &lt;BR /&gt;100 06Dec1999 11 &lt;BR /&gt;120 02Apr2013 11 &lt;BR /&gt;110 01May2003 11 &lt;BR /&gt;130 01Jul2000 11 &lt;BR /&gt;&lt;BR /&gt;I want to get output as for a particular year , particular quarter , sum of total amt.&lt;BR /&gt;e.g for year 1999 o/p should be &lt;BR /&gt;year id quater sum &lt;BR /&gt;1999 130 1 20&lt;BR /&gt;1999 100 4 11 &lt;BR /&gt;&lt;BR /&gt;and so on &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So that is a totally different question than what your original code was trying to do.&lt;/P&gt;
&lt;P&gt;What do you mean by SUM?&amp;nbsp; Sum over just that quarter?&amp;nbsp; Over that year up to that quarter?&amp;nbsp; Over all data for ID up to that quarter?&lt;/P&gt;
&lt;P&gt;Why does your output include only two of the ID values in the input?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749613#M235597</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-22T15:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749615#M235599</link>
      <description>1. The code may looks different but I was checking multiple ways to use if condition  . I was trying to subset data based of qtr value , then wanted to sum it by group &lt;BR /&gt;&lt;BR /&gt;2.  Sum over just that quarter?  Over that year up to that quarter : yes I want to get total value of amount (amt) for a year and quarter &lt;BR /&gt;1999 130 1 20&lt;BR /&gt;1999 100 4 11&lt;BR /&gt; 3. I gave example for 1999 year only but I need output table which consist each year along with quarter  and sum (total of amt) &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749615#M235599</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-22T15:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: If condition in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749616#M235600</link>
      <description>It does not make sense to do summations in a data step. You use PROC MEANS and apply filter to either your output or input data set using a WHERE statement. If your dates are SAS dates you can easily filter specific quarters/years/months as necessary, or sum them at various intervals using formats. &lt;BR /&gt;&lt;BR /&gt;Are you familiar with PROC MEANS? &lt;BR /&gt;Here's a fully worked example of summing data by year, even when the original data is monthly:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb" target="_blank"&gt;https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 16:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-in-SAS/m-p/749616#M235600</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-22T16:02:18Z</dc:date>
    </item>
  </channel>
</rss>

