<?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 how can i convert this to SAS SQL in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909745#M40707</link>
    <description>&lt;P&gt;i'm trying to conver my SQL to SAS but it gives me error in OUTER APPLY AND SELECT TOP 1&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   SELECT a.'PlayerID'n, c.'GamingDate'n
      FROM (SELECT t1.'PlayerPatron ID'n FROM XXX.Player t1 GROUP BY t1.'PlayerID'n) a
   OUTER APPLY
      (SELECT TOP 1 * FROM 
   	     (SELECT t2.'PlayerID'n, t2.'GamingDate'n FROM XXX.FirsRating t2
		  UNION 
          SELECT t3.'PlayerID'n, t3.'Gamingdate'n FROM XXX.SecondRating t3) b
   WHERE a.'PlayerID'n = b.'PlayerID'n ORDER BY b.'PlayerID'n DESC, b.'GamingDate'n DESC) c
   WHERE GamingDate IS NOT NULL;
QUIT;&lt;/PRE&gt;</description>
    <pubDate>Wed, 27 Dec 2023 10:37:32 GMT</pubDate>
    <dc:creator>xander</dc:creator>
    <dc:date>2023-12-27T10:37:32Z</dc:date>
    <item>
      <title>how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909745#M40707</link>
      <description>&lt;P&gt;i'm trying to conver my SQL to SAS but it gives me error in OUTER APPLY AND SELECT TOP 1&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   SELECT a.'PlayerID'n, c.'GamingDate'n
      FROM (SELECT t1.'PlayerPatron ID'n FROM XXX.Player t1 GROUP BY t1.'PlayerID'n) a
   OUTER APPLY
      (SELECT TOP 1 * FROM 
   	     (SELECT t2.'PlayerID'n, t2.'GamingDate'n FROM XXX.FirsRating t2
		  UNION 
          SELECT t3.'PlayerID'n, t3.'Gamingdate'n FROM XXX.SecondRating t3) b
   WHERE a.'PlayerID'n = b.'PlayerID'n ORDER BY b.'PlayerID'n DESC, b.'GamingDate'n DESC) c
   WHERE GamingDate IS NOT NULL;
QUIT;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Dec 2023 10:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909745#M40707</guid>
      <dc:creator>xander</dc:creator>
      <dc:date>2023-12-27T10:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909749#M40709</link>
      <description>&lt;P&gt;SAS SQL doesn't support this functionality and it would be rather hard and inefficient to express in SAS SQL only. It's certainly possible to write SAS code to achieve the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you need to convert to SAS SQL? If your source table is still in the database and you can access this data from SAS then you can also run the DB native SQL and just move the result set to SAS for further processing.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2023 11:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909749#M40709</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-27T11:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909872#M40714</link>
      <description>&lt;P&gt;You don't need to convert it. Just run it as is in SQL Passthru in your original SQL database&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname db odbc datasrc=datasource schema = schema user=user password = password;

proc sql;
 connect using db;
  create table Want as 
  select * from connection to db
  ( SELECT a.'PlayerID'n, c.'GamingDate'n
      FROM (SELECT t1.'PlayerPatron ID'n FROM XXX.Player t1 GROUP BY t1.'PlayerID'n) a
   OUTER APPLY
      (SELECT TOP 1 * FROM 
   	     (SELECT t2.'PlayerID'n, t2.'GamingDate'n FROM XXX.FirsRating t2
		  UNION 
          SELECT t3.'PlayerID'n, t3.'Gamingdate'n FROM XXX.SecondRating t3) b
   WHERE a.'PlayerID'n = b.'PlayerID'n ORDER BY b.'PlayerID'n DESC, b.'GamingDate'n DESC) c
   WHERE GamingDate IS NOT NULL)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Dec 2023 22:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909872#M40714</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-28T22:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909873#M40715</link>
      <description>&lt;P&gt;What SQL dialect is it written for?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What the heck is an OUTER APPLY?&amp;nbsp; That does not look like any flavor of SQL I have ever seen. I have never seen APPLY used in SQL code before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other I can at least make a guess as to the meaning as it looks similar to implementations of WINDOW operations (introduced into standard SQL much later than the version of SQL that SAS implements).&amp;nbsp; But how can it work without an ORDER BY clause?&amp;nbsp; How could it figure out which one is the "top" if they aren't ordered by something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the first subquery makes no sense.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(SELECT t1.'PlayerPatron ID'n FROM XXX.Player t1 GROUP BY t1.'PlayerID'n)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have a GROUP BY but you are not calling any aggregate functions that would use the grouping. And you aren't even selecting the variable that is used to form the grouping.&amp;nbsp; What is that subquery supposed to return?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 22:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909873#M40715</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-28T22:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909874#M40716</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;It's MS SQL&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/u-sql/statements-and-expressions/select/from/select-selecting-from-cross-apply-and-outer-apply" target="_blank"&gt;https://learn.microsoft.com/en-us/u-sql/statements-and-expressions/select/from/select-selecting-from-cross-apply-and-outer-apply&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="heading-wrapper" data-heading-level="h2"&gt;
&lt;H2 id="summary" class="heading-anchor"&gt;Summary&lt;/H2&gt;
&lt;/DIV&gt;
&lt;P&gt;Often when processing some more complex value in a column, such as a byte array, a string, a MAP, ARRAY, JSON or XML document, one would like to extract more than just one value, such as a whole rowset of information per column value.&lt;/P&gt;
&lt;P&gt;U-SQL provides the CROSS APPLY and OUTER APPLY operator which evaluates the rowset generating expressions on the right side against each row and its individual column cells of the rowset on the left. The result is the combination of the columns of both rowsets where the values of the left rowset get repeated for each result of the right rowset expression.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 28 Dec 2023 23:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909874#M40716</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-28T23:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: how can i convert this to SAS SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909878#M40717</link>
      <description>&lt;P&gt;Well that is as clear as mud.&amp;nbsp; But it seems like it is just a LEFT JOIN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although the last WHERE seems to turn it into an INNER JOIN.&lt;/P&gt;
&lt;P&gt;The TOP 1 makes it look like you only one one observation per BY group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge left (in=in1) right1(in=in2) right2(in=in2);
  by ID ;
  if in1 ;
  if first.ID ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Dec 2023 00:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-convert-this-to-SAS-SQL/m-p/909878#M40717</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-29T00:53:25Z</dc:date>
    </item>
  </channel>
</rss>

