<?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: CONVERT SQL SERVER CODE TO SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469783#M285584</link>
    <description>&lt;P&gt;perfect! that's a similar step i took, i connected using the library statement with my poor code just using a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname mydata odbc dsn=WWH;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but your refined code is amazing, thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jun 2018 22:11:06 GMT</pubDate>
    <dc:creator>CatM</dc:creator>
    <dc:date>2018-06-12T22:11:06Z</dc:date>
    <item>
      <title>CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469765#M285578</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to convert some SQL Server code into a SAS proc SQL format but there are a couple of things I have not figured out how to code. Below is the code that I have in SQL server. I know there is an insert function in proc sql for sas but i am not sure how that applies. I have to connect through an odbc connection to gain access to the WWH server where the data is stored so i am not sure how that also changes the code. i have tried to combine the code below into a single proc sql create table statement but it has not been successful. I have also tried to individually create the tables but since some are dependent on the ID from the larger set to select the correct data, i cannot really pull in the entire tables individually and merge later. The declare code i am assuming is like a format step in sql server to assign the variable a length and format. And i am not sure how the quarter variable is being created but i can recreate that from our dates in a separate step. thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DECLARE @AllINF Table&amp;nbsp; (FileDate char(7),IndividualID char(11),ClinicID smallint,[Quarter] varchar(10),&lt;SPAN&gt;RMonth&amp;nbsp;&lt;/SPAN&gt;smallint)&lt;/P&gt;&lt;P&gt;DECLARE @RiskINF Table&amp;nbsp; (FileDate char(7),IndividualID char(11),ClinicID smallint,[Quarter] varchar(10),&lt;SPAN&gt;RMonth&lt;/SPAN&gt; smallint,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MinOdds float, MaxOdds float, OddsRecs int, IsCert int)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** create the table&amp;nbsp;of those to keep;&lt;/P&gt;&lt;P&gt;INSERT INTO @AllINF&amp;nbsp;(FDate,IndivID,ClinicID,[Quarter],&lt;SPAN&gt;RMonth&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;SELECT I.FDate,I.IndivID,I.ClinicID,Q.Quarter,Q.&lt;SPAN&gt;RMonth&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;FROM [WWH].[dbo].IND3_V&amp;nbsp; I&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN dbo.Dates Q&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON I.FDate = Q.DateText&lt;/P&gt;&lt;P&gt;WHERE I.Months = 5&lt;/P&gt;&lt;P&gt;AND&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; I.Categ = 'I'&amp;nbsp; AND I.ClinicID in (7,4,12,18,10)&lt;/P&gt;&lt;P&gt;AND&amp;nbsp;&amp;nbsp; I.FDate BETWEEN '2016-01' and '2018-03'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**find their odds of staying over the last six months as an infant.;&lt;/P&gt;&lt;P&gt;** look at age 14 months to determine if they stayed.;&lt;/P&gt;&lt;P&gt;INSERT INTO @RiskINF&amp;nbsp;(IndivID,ClinicID, [Quarter], RMonth, MaxOdds, MinOdds, OddsRecs, IsCert)&lt;/P&gt;&lt;P&gt;SELECT A.IndivID,A.ClinicID,A.[Quarter],A.RMonth,MAX(Odds.STAY) MaxOdds,MIN(Odds.STAY) MinOdds,Count(*) OddsRecs,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAX(IsCert) IsCert&lt;/P&gt;&lt;P&gt;FROM&amp;nbsp;&amp;nbsp; @AllINF A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN WWH.dbo.ExtOdds Odds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON A.IndivID = Odds.&lt;SPAN&gt;Ind&lt;/SPAN&gt;&lt;SPAN&gt;iv&lt;/SPAN&gt;&lt;SPAN&gt;ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN dbo.Dates D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON Odds.FDate = D.DateText&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND D.&lt;SPAN&gt;RMonth&lt;/SPAN&gt; BETWEEN A.&lt;SPAN&gt;RMonth&lt;/SPAN&gt;-5 AND A.&lt;SPAN&gt;RMonth&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN dbo.Dates Test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON A.&lt;SPAN&gt;RMonth&lt;/SPAN&gt; = Test.&lt;SPAN&gt;RMonth&lt;/SPAN&gt; - 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN WWH.dbo.IND3_V I&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON I.FileDate = Test.DateText&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND I.IndivID = A.IndivID&lt;/P&gt;&lt;P&gt;GROUP BY A.IndivID,A.ClinicID,A.[Quarter],A.RMONTH&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having Count(*) = 6 AND MIN(Odds.Stay) &amp;lt; 1.25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT [Quarter],ClinicID, Count(*) INF, Sum(Cert) Cert&lt;/P&gt;&lt;P&gt;FROM&amp;nbsp;&amp;nbsp; @RiskINF&lt;/P&gt;&lt;P&gt;GROUP BY [Quarter],ClinicID&lt;/P&gt;&lt;P&gt;ORDER BY ClinicID,[Quarter]&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 21:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469765#M285578</guid>
      <dc:creator>CatM</dc:creator>
      <dc:date>2018-06-12T21:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469767#M285579</link>
      <description>Check the examples section of the documentation to see how things work. The first example is about creating a table and INSERT to create data.&lt;BR /&gt;&lt;A href="http://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n1ncn0pznd8wrln1tnp3xdxjz9xz.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n1ncn0pznd8wrln1tnp3xdxjz9xz.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Tue, 12 Jun 2018 21:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469767#M285579</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-12T21:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469769#M285580</link>
      <description>&lt;P&gt;thanks i understood that part but i have to connect to odbc so its not as simple as just calling up the tables from a library. i wanted to know how to do this with and odbc connection to call up the tables from the WWH server. I keep getting errors when i try to use an Insert into statement so i need to know what i am doing wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is how i normally connect&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname data "G:\catdata";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;CONNECT to odbc(dsn=WWH);&lt;BR /&gt;CREATE TABLE Data.TEST1 as SELECT * from connection to odbc&lt;BR /&gt;(SELECT * from WWH.dbo.IND3_V )&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 21:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469769#M285580</guid>
      <dc:creator>CatM</dc:creator>
      <dc:date>2018-06-12T21:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469772#M285581</link>
      <description>&lt;P&gt;Actually, that type of SQL is pass through SQL and that requires that you use the native language on the database. All SAS does when you use that type of connection is pass the code directly to the server. However, you do need to ensure that the types are correct and that you're only referencing data on the server.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to mix data from your local drive, a different server, and the ODBC connection you need a different approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214106"&gt;@CatM&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks i understood that part but i have to connect to odbc so its not as simple as just calling up the tables from a library. i wanted to know how to do this with and odbc connection to call up the tables from the WWH server. I keep getting errors when i try to use an Insert into statement so i need to know what i am doing wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is how i normally connect&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname data "G:\catdata";&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;CONNECT to odbc(dsn=WWH);&lt;BR /&gt;CREATE TABLE Data.TEST1 as SELECT * from connection to odbc&lt;BR /&gt;(SELECT * from WWH.dbo.IND3_V )&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 21:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469772#M285581</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-12T21:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469776#M285582</link>
      <description>&lt;P&gt;OK thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what would be the best option to merge the local dataset with the data from an ODBC connection? i have been attempting to use the create table command rather than the insert into in sql but i still cannot get the data to merge because as you said it is two different types of locations the data is saved under.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all your help&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 22:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469776#M285582</guid>
      <dc:creator>CatM</dc:creator>
      <dc:date>2018-06-12T22:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469781#M285583</link>
      <description>&lt;P&gt;Use native PROC SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname sData ODBC dsn=your_dsn schema=dbo;

proc sql;
create table want as 
select * 
from sData.Table1 as t1
left join whh.Table2 as t2
on t1.key=t2.key;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on how big your data sets are, this may work well or may not.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 22:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469781#M285583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-12T22:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: CONVERT SQL SERVER CODE TO SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469783#M285584</link>
      <description>&lt;P&gt;perfect! that's a similar step i took, i connected using the library statement with my poor code just using a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname mydata odbc dsn=WWH;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but your refined code is amazing, thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 22:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CONVERT-SQL-SERVER-CODE-TO-SAS/m-p/469783#M285584</guid>
      <dc:creator>CatM</dc:creator>
      <dc:date>2018-06-12T22:11:06Z</dc:date>
    </item>
  </channel>
</rss>

