<?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: Proc SQL equivalent for If first. then do if last. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816781#M322423</link>
    <description>&lt;P&gt;he has the equivalent in his paper&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings17/0930-2017.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/0930-2017.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2022 01:20:47 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-06-07T01:20:47Z</dc:date>
    <item>
      <title>Proc SQL equivalent for If first. then do if last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816775#M322418</link>
      <description>&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hello Everyone:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to write the following SAS data step in Proc SQL? I have been struggled for a long time. Thank you so much in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data hsshow(/*drop=days_span*/);
    set show_all; 
    by member_i prognum mon;    
    if first.mon then days_elig=0;
	days_elig + days_span;
    if days_elig gt days_in_mon then days_elig=days_in_mon;
	days_gap = days_in_mon - days_elig;
	if prognum in ("MC") then do;
		if days_gap = days_in_mon then do; 
			month_full=0; month_gap=1; 
			end;
        else do; month_full=1; month_gap=0; days_gap=0;	
		end;   
		end;
	else do;
	   if days_gap &amp;gt; 0 then do; 
            month_full=0; month_gap=1; 
	   end; 
	   else do; month_gap=0; month_full=1; 
	   end;
	end;
	if last.mon then do;
	       days_elig = days_in_mon - days_gap;count=1;
	       output; 
	end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 23:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816775#M322418</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2022-06-06T23:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for If first. then do if last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816777#M322420</link>
      <description>&lt;P&gt;Unfortunately there isn't any. Nor is there any concept of conditional processing of rows. That functionality is available in SQL stored procedures - these are only available in external RDBMSs typically. There is no equivalent in SAS SQL. Why do you want to change to SQL?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 23:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816777#M322420</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-06-06T23:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for If first. then do if last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816781#M322423</link>
      <description>&lt;P&gt;he has the equivalent in his paper&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings17/0930-2017.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/0930-2017.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 01:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816781#M322423</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-06-07T01:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for If first. then do if last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816783#M322425</link>
      <description>&lt;P&gt;Not easily especially with a few of them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's much easier to do in a data step or a different language. Is SQL your only option? What flavour of SQL? Sometimes SQL variants have different methods of implementing this type of functionality.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For doing this code conversion, indenting your code also makes it much easier to read.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hsshow(/*drop=days_span*/);
    set show_all; 
    by member_i prognum mon;    
    if first.mon then days_elig=0;
	days_elig + days_span;
    if days_elig gt days_in_mon then days_elig=days_in_mon;
	days_gap = days_in_mon - days_elig;
	if prognum in ("MC") then do;
		if days_gap = days_in_mon then do; 
			month_full=0; month_gap=1; 
			end;
        else do; month_full=1; month_gap=0; days_gap=0;	
		end;   
		end;
	else do;
	   if days_gap &amp;gt; 0 then do; 
            month_full=0; month_gap=1; 
	   end; 
	   else do; month_gap=0; month_full=1; 
	   end;
	end;
	if last.mon then do;
	       days_elig = days_in_mon - days_gap;count=1;
	       output; 
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2022 01:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816783#M322425</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-07T01:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for If first. then do if last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816808#M322445</link>
      <description>&lt;P&gt;We are converting all our projects from Base SAS to SAS DI Studio. In SAS DI Studio, most transformations are based on SQL instead of data step. Thus I am trying to translate our code from SAS data step to Proc SQL. I think I will use User Written transformation in the SAS DI studio to include this data step, that works. Thank you for answering my question~&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 05:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-If-first-then-do-if-last/m-p/816808#M322445</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2022-06-07T05:30:41Z</dc:date>
    </item>
  </channel>
</rss>

