<?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: Conditional expression that evaluates only the first row of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697089#M213011</link>
    <description>&lt;P&gt;You need to retain the once evaluated value of "Type":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat Date1 Date2 ddmmyy10.;
   format Date1 Date2 ddmmyys10.;
   input Date1 Date2;
   datalines;
31/03/2018 31/03/2018
30/04/2018 31/03/2019
31/05/2018 31/03/2020 
;
run;

data want;
   set have;
   length Type $ 3;
   retain Type;
   
   if _n_ = 1 then do;
      Type = ifc(Date1 = Date2, 'INI', 'EXR');
   end;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Nov 2020 09:44:35 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-11-06T09:44:35Z</dc:date>
    <item>
      <title>Conditional expression that evaluates only the first row of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697080#M213008</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATE1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;31/03/2018&amp;nbsp; 31/03/2018&lt;/P&gt;&lt;P&gt;30/04/2018&amp;nbsp; 31/03/2019&lt;/P&gt;&lt;P&gt;31/05/2018&amp;nbsp; 31/03/2020&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a new variable, TYPE, that will have the same value for all rows. I need a program that evaluates the first values of DATE1 and DATE2:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; - If, for the first row, DATE1=DATE2 then this variable will always take the value 'INI';&lt;/P&gt;&lt;P&gt;&amp;nbsp; - If, for the first row, DATE1 not eq DATE2, then this variable will always take the value 'EXR'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my example, the data with the new variable would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATE1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TYPE&lt;/P&gt;&lt;P&gt;31/03/2018&amp;nbsp; 31/03/2018&amp;nbsp; &amp;nbsp;INI&lt;/P&gt;&lt;P&gt;30/04/2018&amp;nbsp; 31/03/2019&amp;nbsp; &amp;nbsp;INI&lt;/P&gt;&lt;P&gt;31/05/2018&amp;nbsp; 31/03/2020&amp;nbsp; &amp;nbsp;INI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried conditional expressions with case when in proc sql but I am only able to obtain an expression that evaluates all rows one by one, thus not generating the same value for all rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 09:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697080#M213008</guid>
      <dc:creator>mariapf</dc:creator>
      <dc:date>2020-11-06T09:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional expression that evaluates only the first row of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697085#M213010</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a data step with a retain statement :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length TYPE $3.;
    retain TYPE;
    if _N_=1 then TYPE=ifc(DATE1=DATE2,'INI','EXR');
run;    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Nov 2020 09:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697085#M213010</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-11-06T09:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional expression that evaluates only the first row of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697089#M213011</link>
      <description>&lt;P&gt;You need to retain the once evaluated value of "Type":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat Date1 Date2 ddmmyy10.;
   format Date1 Date2 ddmmyys10.;
   input Date1 Date2;
   datalines;
31/03/2018 31/03/2018
30/04/2018 31/03/2019
31/05/2018 31/03/2020 
;
run;

data want;
   set have;
   length Type $ 3;
   retain Type;
   
   if _n_ = 1 then do;
      Type = ifc(Date1 = Date2, 'INI', 'EXR');
   end;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Nov 2020 09:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697089#M213011</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-06T09:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional expression that evaluates only the first row of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697821#M213332</link>
      <description>&lt;P&gt;Thank you so much! This code has worked for me&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 08:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-expression-that-evaluates-only-the-first-row-of-data/m-p/697821#M213332</guid>
      <dc:creator>mariapf</dc:creator>
      <dc:date>2020-11-10T08:15:11Z</dc:date>
    </item>
  </channel>
</rss>

