<?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: Converting SQL code into SAS code in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709335#M26701</link>
    <description>&lt;P&gt;Run PROC CONTENTS on your source datasets so you can see how the variables are defined.&lt;/P&gt;
&lt;P&gt;If the values of DischargeDTS look like "&lt;SPAN&gt;2015-06-09 00:00:00.0000000" then they are probably character strings as most SAS datetime formats will not display in that way.&amp;nbsp; So you will want to first convert them to actual dates before trying to use the MONTH() or YEAR() functions.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month(input(DischargeDTS,yymmdd10.)) &amp;gt; 9 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Also you need to figure out which of CPT and HCPCS is numeric and which is character.&amp;nbsp; Either way you probably will want to create your new HCPCS variable as a character string.&amp;nbsp; So if CPT is character already your code might need to be&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,CASE WHEN LENGTH(c.CPT) ^= 5 
		THEN cats(c.HCPCS)
		ELSE c.CPT 
END AS HCPCS&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Jan 2021 22:26:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-01-04T22:26:08Z</dc:date>
    <item>
      <title>Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709311#M26694</link>
      <description>&lt;P&gt;Good afternoon all&lt;/P&gt;&lt;P&gt;I am trying to convert SQL code into SAS code and keep getting multiple errors, I'm guessing because some of the expressions I am using do not translate. Can anyone give me any suggestions?&lt;/P&gt;&lt;P&gt;Here is the code I am using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE work.first_chemo AS 
SELECT 
CASE WHEN Month(DischargeDTS) &amp;gt; 9 
	 THEN YEAR(DischargeDTS) + 1 
	 ELSE YEAR(DischargeDTS)
END as Fiscal_Year
, b.MRN AS mrn
, MIN(DischargeDTS) AS date
	,CASE WHEN LEN(c.CPT) ^= 5 
		THEN c.HCPCS 
		ELSE c.CPT 
END AS HCPCS
FROM epicfin.HospitalAccount a 
	LEFT JOIN epicpat.Patient b
	 	ON a.PatientID= b.PatientID
	LEFT JOIN Epicfin.HospitalTransaction c
		ON a.HospitalAccountID = c.HospitalAccountID
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and this is the log with the errors:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         PROC SQL;
27         CREATE TABLE work.first_chemo AS
28         SELECT
29         CASE WHEN Month(DischargeDTS) &amp;gt; 9
30         	 THEN YEAR(DischargeDTS) + 1
31         	 ELSE YEAR(DischargeDTS)
32         END as Fiscal_Year
33         , b.MRN AS mrn
34         , MIN(DischargeDTS) AS date
35         	,CASE WHEN LEN(c.CPT) ^= 5
36         		THEN c.HCPCS
37         		ELSE c.CPT
38         END AS HCPCS
39         FROM epicfin.HospitalAccount a
40         	LEFT JOIN epicpat.Patient b
41         	 	ON a.PatientID= b.PatientID
42         	LEFT JOIN Epicfin.HospitalTransaction c
43         		ON a.HospitalAccountID = c.HospitalAccountID
44         ;
ERROR: Function MONTH requires a numeric expression as argument 1.
ERROR: Expression using greater than (&amp;gt;) has components that are of different data types.
ERROR: Function YEAR requires a numeric expression as argument 1.
ERROR: Expression using addition (+) requires numeric types.
ERROR: Function YEAR requires a numeric expression as argument 1.
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.
ERROR: Function LEN could not be located.
ERROR: Expression using not equals (^=) has components that are of different data types.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
44       !  QUIT;
NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any assistance provided would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 20:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709311#M26694</guid>
      <dc:creator>wheddingsjr</dc:creator>
      <dc:date>2021-01-04T20:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709313#M26695</link>
      <description>&lt;P&gt;MONTH and YEAR functions only works on numeric variables. The error message is telling you that DischargeDTS is not numeric. So you would have to convert it to numeric. If you can show us a typical value of DischargeDTS, we can tell you how to convert it. Furthermore, DischargeDTS needs to be an actual SAS date, which is the number of days since 01JAN1960.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 20:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709313#M26695</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-04T20:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709318#M26696</link>
      <description>&lt;P&gt;Also If "LEN(c.cpt)" is supposed to return the number of characters then the function name is LENGTH in SAS.&amp;nbsp; Otherwise you will need to explain what "LEN" is supposed to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 21:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709318#M26696</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-04T21:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709328#M26699</link>
      <description>Thanks Ballard, yes the function is Length.</description>
      <pubDate>Mon, 04 Jan 2021 21:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709328#M26699</guid>
      <dc:creator>wheddingsjr</dc:creator>
      <dc:date>2021-01-04T21:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709331#M26700</link>
      <description>Thanks Paige&lt;BR /&gt;&lt;BR /&gt;In the SAS table the DischargeDTS vaue looks like this:&lt;BR /&gt;2015-06-09 00:00:00.0000000&lt;BR /&gt;&lt;BR /&gt;when copied and pasted to excel it looks like:&lt;BR /&gt;6/9/2015 12:00:00 AM&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jan 2021 22:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709331#M26700</guid>
      <dc:creator>wheddingsjr</dc:creator>
      <dc:date>2021-01-04T22:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709335#M26701</link>
      <description>&lt;P&gt;Run PROC CONTENTS on your source datasets so you can see how the variables are defined.&lt;/P&gt;
&lt;P&gt;If the values of DischargeDTS look like "&lt;SPAN&gt;2015-06-09 00:00:00.0000000" then they are probably character strings as most SAS datetime formats will not display in that way.&amp;nbsp; So you will want to first convert them to actual dates before trying to use the MONTH() or YEAR() functions.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month(input(DischargeDTS,yymmdd10.)) &amp;gt; 9 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Also you need to figure out which of CPT and HCPCS is numeric and which is character.&amp;nbsp; Either way you probably will want to create your new HCPCS variable as a character string.&amp;nbsp; So if CPT is character already your code might need to be&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,CASE WHEN LENGTH(c.CPT) ^= 5 
		THEN cats(c.HCPCS)
		ELSE c.CPT 
END AS HCPCS&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jan 2021 22:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709335#M26701</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-04T22:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL code into SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709463#M26712</link>
      <description>Thanks Tom&lt;BR /&gt;&lt;BR /&gt;That worked perfectlt!!!!</description>
      <pubDate>Tue, 05 Jan 2021 16:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-SQL-code-into-SAS-code/m-p/709463#M26712</guid>
      <dc:creator>wheddingsjr</dc:creator>
      <dc:date>2021-01-05T16:58:09Z</dc:date>
    </item>
  </channel>
</rss>

