<?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 INTNX function on cleaning data in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875865#M10952</link>
    <description>&lt;P&gt;Im trying to clean the data by &lt;FONT color="#0000FF"&gt;adding 1 year&lt;/FONT&gt; to &lt;FONT color="#0000FF"&gt;Date_Received&lt;/FONT&gt; if &lt;FONT color="#000000"&gt;Incident_Date &amp;gt; Date Received&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table sq.Claims_Cleaned as
	Select Distinct
		Claim_Number,
			(Case 
			when Incident_Date &amp;gt; Date_Received then &lt;FONT color="#FF0000"&gt;INTNX(YEAR,Date_Received,1,S)&lt;/FONT&gt; else Date_Received
			End) as Date_Received,
		Incident_Date,
			(Case 
			when Airport_Code is null then "Unknown" else Airport_Code 
			end) as Airport_Code,
		Airport_Name,
			(Case 
			when Claim_Type is null then "Unknown"
			when Claim_Type contains "/" then scan(Claim_Type,1,"/")
			else Claim_Type 
			end) as Claim_Type,			
			(Case 
			when Claim_Site is null then "Unknown" else Claim_Site 
			end) as Claim_Site,
		Close_Amount,
			(Case 
			when Disposition is null then "Unknown" else Disposition 
			end) as Disposition,
		StateName,
		State,
		County,
		City
	From SQ.ClaimsRaw;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I hit an error saying the column year and S are not found in the table.&lt;/P&gt;&lt;P&gt;May I know why the error happens instead of adding 1 year to Date_Received?&lt;/P&gt;&lt;P&gt;The Date_Received is in format = date9.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         proc sql;
 74         create table sq.Claims_Cleaned as
 75         Select Distinct
 76         Claim_Number,
 77         (Case
 78         when Incident_Date &amp;gt; Date_Received then INTNX(YEAR,Date_Received,1,S) else Date_Received
 79         End) as Date_Received,
 80         Incident_Date,
 81         (Case
 82         when Airport_Code is null then "Unknown" else Airport_Code
 83         end) as Airport_Code,
 84         Airport_Name,
 85         (Case
 86         when Claim_Type is null then "Unknown"
 87         when Claim_Type contains "/" then scan(Claim_Type,1,"/")
 88         else Claim_Type
 89         end) as Claim_Type,
 90         (Case
 91         when Claim_Site is null then "Unknown" else Claim_Site
 92         end) as Claim_Site,
 93         Close_Amount,
 94         (Case
 95         when Disposition is null then "Unknown" else Disposition
 96         end) as Disposition,
 97         StateName,
 98         State,
 99         County,
 100        City
 101        From SQ.ClaimsRaw;
&lt;FONT color="#FF0000"&gt; ERROR: The following columns were not found in the contributing tables: S, YEAR.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 May 2023 18:13:00 GMT</pubDate>
    <dc:creator>ChrisWoo</dc:creator>
    <dc:date>2023-05-15T18:13:00Z</dc:date>
    <item>
      <title>INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875865#M10952</link>
      <description>&lt;P&gt;Im trying to clean the data by &lt;FONT color="#0000FF"&gt;adding 1 year&lt;/FONT&gt; to &lt;FONT color="#0000FF"&gt;Date_Received&lt;/FONT&gt; if &lt;FONT color="#000000"&gt;Incident_Date &amp;gt; Date Received&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table sq.Claims_Cleaned as
	Select Distinct
		Claim_Number,
			(Case 
			when Incident_Date &amp;gt; Date_Received then &lt;FONT color="#FF0000"&gt;INTNX(YEAR,Date_Received,1,S)&lt;/FONT&gt; else Date_Received
			End) as Date_Received,
		Incident_Date,
			(Case 
			when Airport_Code is null then "Unknown" else Airport_Code 
			end) as Airport_Code,
		Airport_Name,
			(Case 
			when Claim_Type is null then "Unknown"
			when Claim_Type contains "/" then scan(Claim_Type,1,"/")
			else Claim_Type 
			end) as Claim_Type,			
			(Case 
			when Claim_Site is null then "Unknown" else Claim_Site 
			end) as Claim_Site,
		Close_Amount,
			(Case 
			when Disposition is null then "Unknown" else Disposition 
			end) as Disposition,
		StateName,
		State,
		County,
		City
	From SQ.ClaimsRaw;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I hit an error saying the column year and S are not found in the table.&lt;/P&gt;&lt;P&gt;May I know why the error happens instead of adding 1 year to Date_Received?&lt;/P&gt;&lt;P&gt;The Date_Received is in format = date9.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         proc sql;
 74         create table sq.Claims_Cleaned as
 75         Select Distinct
 76         Claim_Number,
 77         (Case
 78         when Incident_Date &amp;gt; Date_Received then INTNX(YEAR,Date_Received,1,S) else Date_Received
 79         End) as Date_Received,
 80         Incident_Date,
 81         (Case
 82         when Airport_Code is null then "Unknown" else Airport_Code
 83         end) as Airport_Code,
 84         Airport_Name,
 85         (Case
 86         when Claim_Type is null then "Unknown"
 87         when Claim_Type contains "/" then scan(Claim_Type,1,"/")
 88         else Claim_Type
 89         end) as Claim_Type,
 90         (Case
 91         when Claim_Site is null then "Unknown" else Claim_Site
 92         end) as Claim_Site,
 93         Close_Amount,
 94         (Case
 95         when Disposition is null then "Unknown" else Disposition
 96         end) as Disposition,
 97         StateName,
 98         State,
 99         County,
 100        City
 101        From SQ.ClaimsRaw;
&lt;FONT color="#FF0000"&gt; ERROR: The following columns were not found in the contributing tables: S, YEAR.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2023 18:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875865#M10952</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-15T18:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875869#M10953</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; My suggestion is that you review the INTNX documentation. One of the requirements for some of the arguments is that they need to be quoted. Here's the web site: &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm&lt;/A&gt; and here are some examples from that page:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1684174718656.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83990iB7E91BFA9A8CAB7C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1684174718656.png" alt="Cynthia_sas_0-1684174718656.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 18:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875869#M10953</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2023-05-15T18:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875870#M10954</link>
      <description>&lt;P&gt;You are asking for those variables in your INTNX() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INTNX(YEAR,Date_Received,1,S)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The fist and last arguments to INTNX() need to be character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INTNX('YEAR',Date_Received,1,'S')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You probably will also want to attach a format to that new variable so it prints in a way that humans will recognize as a date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;as Date_Received  format=yymmdd10. ,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2023 18:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875870#M10954</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-15T18:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875879#M10955</link>
      <description>FYI - you should look into the COALESCE/COALESCEC function as well. for your Claim Site, Disposition, airport_code variables.</description>
      <pubDate>Mon, 15 May 2023 19:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875879#M10955</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-15T19:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875904#M10956</link>
      <description>But I remember i used it in macro statements %sysfunc(intnx(day,%sysfunc(today()),-1,s))&lt;BR /&gt;&lt;BR /&gt;I didnt put quote and its working fine</description>
      <pubDate>Tue, 16 May 2023 01:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875904#M10956</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-16T01:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875905#M10957</link>
      <description>Any suggested code? I not sure how to use COALESCEC() to replace missing value&lt;BR /&gt;&lt;BR /&gt;Therefore, i chose to use case/when/then to list my condition and replace the missing value to “unknown”.</description>
      <pubDate>Tue, 16 May 2023 01:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875905#M10957</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-16T01:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875912#M10958</link>
      <description>&lt;P&gt;The macro processor is a completely different language than that used in SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code a stream of letters like YEAR or S is used to indicate a variable name.&amp;nbsp; A literal text string has to be enclosed in quotes so SAS knows you don't mean a variable name.&amp;nbsp; A format reference has to include a period so SAS knows you didn't mean a variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your macro code example the %SYSFUNC() macro processor function is responsible for taking the text in your code and passing it to the function call as the right type of value.&amp;nbsp;&amp;nbsp;To the macro processor everything is text.&amp;nbsp; If you add quotes they are considered part of the text.&amp;nbsp; So if you tried to use this in macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(intnx('day',%sysfunc(today()),-1,'s'))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro processor would pass the quotes to the INTNX() function and it would complain that 'day' is not a valid interval since it starts with a quote and not a letter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be like trying to do this in SAS code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx("'day'",today(),-1,"'s'")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS There is no need to use INTNX() when the interval you are moving is in the units that the values are stored in.&amp;nbsp; So no need to use the DAY interval for DATE value or the SECOND interval with TIME or DATETIME values.&amp;nbsp; Note you do need to use the DTDAY interval to adjust DATETIME values by day intervals since datatime values are stored in seconds not in days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to subtract one day from a date just subtract 1 from the date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;today()-1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or in macro code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%eval( %sysfunc(today()) -1 )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 03:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875912#M10958</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T03:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875913#M10959</link>
      <description>&lt;P&gt;So this SQL code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Case when Airport_Code is null then "Unknown" else Airport_Code end as Airport_Code&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is just a complex way to write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coalesce(Airport_Code,"Unknown") as Airport_Code&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in SQL code COALESCE() can be used for either numeric or character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if want to use it in normal SAS code, like a DATA STEP, then the COALESCE() function only works with numeric values.&amp;nbsp; For character values you need to use the COALESCEC() function.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 03:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875913#M10959</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T03:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: INTNX function on cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875935#M10960</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Use Maxim 1.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me Google it for you:&lt;/P&gt;
&lt;P&gt;Query: "SAS 9.4 COALESCEC() function"&lt;/P&gt;
&lt;P&gt;Result (the first from the top):&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2ref/n0crpo0xd76wb3n1poba9wmu1a6q.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2ref/n0crpo0xd76wb3n1poba9wmu1a6q.htm&lt;/A&gt;&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>Tue, 16 May 2023 09:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/INTNX-function-on-cleaning-data/m-p/875935#M10960</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-16T09:00:50Z</dc:date>
    </item>
  </channel>
</rss>

