<?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: I in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470244#M120375</link>
    <description>&lt;P&gt;Maxim 3: Know your data.&lt;/P&gt;
&lt;P&gt;Do a proc contents on table Step1.Earlist_grant_date_earlist_id2 and look for the type and display format of earliest_grant_date_final.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jun 2018 10:59:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-06-14T10:59:17Z</dc:date>
    <item>
      <title>Count the number of distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470225#M120363</link>
      <description>&lt;P&gt;hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to count the number of distinct pat_bubln_id of earliest_filing_id by following codes,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

create table step1.citatins_of_earliest_filing_id as
SELECT 
t6.psn_name,
t1.earliest_filing_id,
count(distinct t3.pat_publn_id) AS cites_in_2006
from Sasdata.Applicationsnew as t1
join Step1.Earlist_grant_date_earlist_id2 as t2 on t1.appln_id=t2.appln_id
join Sasdata.Publicationsnew as t2b on t2.appln_id=t2b.appln_id
join Sasdata.Citations as t3 on t2b.pat_publn_id=t3.cited_pat_publn_id
join Sasdata.Publicationsnew as t4 on t3.pat_publn_id=t4.pat_publn_id
join Sasdata.Personapplication as t5 on t1.appln_id = t5.appln_id
join Sasdata.Companies as t6 on t5.person_id = t6.person_id
where 
year(t2.granted_date) &amp;lt;&amp;gt; 9999
and t2.granted_date &amp;gt;= '2000-01-01'
and t2.granted_date &amp;lt;= '2000-12-31'
and t2b.publn_first_grant=1
and t4.publn_date &amp;lt;= DATE_ADD(t2.Earliest_grant_date_final,INTERVAL 3 YEAR)
group by co.psn_name, ap.earliest_filing_id
order by co.psn_name, ap.earliest_filing_id
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but the result shows,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;292  proc sql;
293
294  create table step1.citatins_of_earliest_filing_id as
295  SELECT
296  t6.psn_name,
297  t1.earliest_filing_id,
298  count(distinct t3.pat_publn_id) AS cites_in_2006
299  from Sasdata.Applicationsnew as t1
300  join Step1.Earlist_grant_date_earlist_id2 as t2 on t1.appln_id=t2.appln_id
301  join Sasdata.Publicationsnew as t2b on t2.appln_id=t2b.appln_id
302  join Sasdata.Citations as t3 on t2b.pat_publn_id=t3.cited_pat_publn_id
303  join Sasdata.Publicationsnew as t4 on t3.pat_publn_id=t4.pat_publn_id
304  join Sasdata.Personapplication as t5 on t1.appln_id = t5.appln_id
305  join Sasdata.Companies as t6 on t5.person_id = t6.person_id
306  where
307  year(t2.granted_date) &amp;lt;&amp;gt; 9999
308  and t2.granted_date &amp;gt;= '2000-01-01'
309  and t2.granted_date &amp;lt;= '2000-12-31'
310  and t2b.publn_first_grant=1
311  and t4.publn_date &amp;lt;= DATE_ADD(t2.Earliest_grant_date_final,INTERVAL 3 YEAR)
                                                                         -
                                                                         22
                                                                         200
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, ), *, **, +, ',', -, '.',
              /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS,
              LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.

ERROR 200-322: The symbol is not recognized and will be ignored.

312  group by co.psn_name, ap.earliest_filing_id
313  order by co.psn_name, ap.earliest_filing_id
314  ;
NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "not equals".
315
316  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could you please give me some suggestions to improve the codes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 12:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470225#M120363</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-06-14T12:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470226#M120364</link>
      <description>&lt;P&gt;This:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;DATE_ADD&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Earliest_grant_date_final&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;INTERVAL &lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;YEAR&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;Is not an ANSI SQL piece of code.&amp;nbsp; I suspect you have got this code from a database which has this "date_add" function.&amp;nbsp; You will need to replace it with either ANSI SQL compliant code, or use SAS functions, or you could pass through to the original database and execute it there.&amp;nbsp; As for SAS syntax:&lt;/P&gt;
&lt;PRE&gt;intnx('year',t2.earliest_grant_date_final,3)&lt;/PRE&gt;
&lt;P&gt;Should be nearly there.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 09:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470226#M120364</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-14T09:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470230#M120367</link>
      <description>&lt;P&gt;thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I have a new problem for this code now. By using following codes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT 
t6.psn_name,
t1.earliest_filing_id,
count(distinct t3.pat_publn_id) AS cites_in_2006
from Sasdata.Applicationsnew as t1
join Step1.Earlist_grant_date_earlist_id2 as t2 on t1.appln_id=t2.appln_id
join Sasdata.Publicationsnew as t2b on t2.appln_id=t2b.appln_id
join Sasdata.Citations as t3 on t2b.pat_publn_id=t3.cited_pat_publn_id
join Sasdata.Publicationsnew as t4 on t3.pat_publn_id=t4.pat_publn_id
join Sasdata.Personapplication as t5 on t1.appln_id = t5.appln_id
join Sasdata.Companies as t6 on t5.person_id = t6.person_id
where 
year(t2.Earliest_grant_date_final) &amp;lt;&amp;gt; 9999
and t2.Earliest_grant_date_final &amp;gt;= '2006-01-01'
and t2.Earliest_grant_date_final &amp;lt;= '2006-12-31'
and t2b.publn_first_grant=1
and t4.publn_date &amp;lt;= intnx('year',t2.earliest_grant_date_final,3)
group by t6.psn_name, t1.earliest_filing_id
order by t6.psn_name, t1.earliest_filing_id
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the result shows,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;367  proc sql;
368
369  create table step1.citatins_of_earliest_filing_id as
370  SELECT
371  t6.psn_name,
372  t1.earliest_filing_id,
373  count(distinct t3.pat_publn_id) AS cites_in_2006
374  from Sasdata.Applicationsnew as t1
375  join Step1.Earlist_grant_date_earlist_id2 as t2 on t1.appln_id=t2.appln_id
376  join Sasdata.Publicationsnew as t2b on t2.appln_id=t2b.appln_id
377  join Sasdata.Citations as t3 on t2b.pat_publn_id=t3.cited_pat_publn_id
378  join Sasdata.Publicationsnew as t4 on t3.pat_publn_id=t4.pat_publn_id
379  join Sasdata.Personapplication as t5 on t1.appln_id = t5.appln_id
380  join Sasdata.Companies as t6 on t5.person_id = t6.person_id
381  where
382  year(t2.Earliest_grant_date_final) &amp;lt;&amp;gt; 9999
383  and t2.Earliest_grant_date_final &amp;gt;= '2000-01-01'
384  and t2.Earliest_grant_date_final &amp;lt;= '2000-12-31'
385  and t2b.publn_first_grant=1
386  and t4.publn_date &amp;lt;= intnx('year',t2.earliest_grant_date_final,3)
387  group by t6.psn_name, t1.earliest_filing_id
388  order by t6.psn_name, t1.earliest_filing_id
389  ;
NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "not equals".
NOTE: Data file SASDATA.PUBLICATIONSNEW.DATA is in a format that is native to another host, or the
      file encoding does not match the session encoding. Cross Environment Data Access will be
      used, which might require additional CPU resources and might reduce performance.
NOTE: Data file SASDATA.PUBLICATIONSNEW.DATA is in a format that is native to another host, or the
      file encoding does not match the session encoding. Cross Environment Data Access will be
      used, which might require additional CPU resources and might reduce performance.
&lt;STRONG&gt;ERROR: Expression using IN has components that are of different data types.&lt;/STRONG&gt;
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC
      SQL WHERE clause optimization.
390
391  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.55 seconds
      cpu time            0.09 seconds


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But there is no IN in&amp;nbsp;the codes, could you please show me how to improve it ?&lt;/P&gt;&lt;P&gt;thanks a lot.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 09:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470230#M120367</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-06-14T09:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470231#M120368</link>
      <description>&lt;P&gt;You are mixing up types somewhere:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token function"&gt;year&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Earliest_grant_date_final&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;9999&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;383&lt;/SPAN&gt; and t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Earliest_grant_date_final &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'2000-01-01'&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;384&lt;/SPAN&gt; and t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Earliest_grant_date_final &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'2000-12-31'&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;385&lt;/SPAN&gt; and t2b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;publn_first_grant&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;386&lt;/SPAN&gt; and t4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;publn_date &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'year'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;earliest_grant_date_final&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;Is earliest_grant_date_final a numeric date value - as indicated by the first line, if so line 2 and 3 are invalid as you can't compare a text string with a number.&amp;nbsp; If its a character varaible then line 1 and 5 are incorrect as they assume numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will assume earliest_grant_date_final is a character:&lt;/P&gt;
&lt;PRE&gt;year(input(t2.Earliest_grant_date_final,yymmdd10.)) &amp;lt;&amp;gt; 9999
and input(t2.Earliest_grant_date_final,yymmdd10.) &amp;gt;= '01Jan2000'd
and input(t2.Earliest_grant_date_final,yymmdd10.) &amp;lt;= '31Dec2000'd
and t2b.publn_first_grant=1
and t4.publn_date &amp;lt;= intnx('year',input(t2.earliest_grant_date_final,yymmdd10.),3)&lt;/PRE&gt;
&lt;P&gt;Something like that.&amp;nbsp; I would really read up on how dates are stored/used in SAS as they are different from a database.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 10:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470231#M120368</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-14T10:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470235#M120369</link>
      <description>&lt;P&gt;thanks but the result like this,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;443  proc sql;
444
445  create table step1.citatins_of_earliest_filing_id as
446  SELECT
447  t6.psn_name,
448  t1.earliest_filing_id,
449  count(distinct t3.pat_publn_id) AS cites_2006
450  from Sasdata.Applicationsnew as t1
451  join Step1.Earlist_grant_date_earlist_id2 as t2 on t1.appln_id=t2.appln_id
452  join Sasdata.Publicationsnew as t2b on t2.appln_id=t2b.appln_id
453  join Sasdata.Citations as t3 on t2b.pat_publn_id=t3.cited_pat_publn_id
454  join Sasdata.Publicationsnew as t4 on t3.pat_publn_id=t4.pat_publn_id
455  join Sasdata.Personapplication as t5 on t1.appln_id = t5.appln_id
456  join Sasdata.Companies as t6 on t5.person_id = t6.person_id
457  where
458  year(input(t2.Earliest_grant_date_final,yymmdd10.)) &amp;lt;&amp;gt; 9999
459  and input(t2.Earliest_grant_date_final,yymmdd10.) &amp;gt;= '01Jan2000'd
460  and input(t2.Earliest_grant_date_final,yymmdd10.) &amp;lt;= '31Dec2000'd
461  and t2b.publn_first_grant=1
462  and t4.publn_date &amp;lt;= intnx('year',input(t2.earliest_grant_date_final,yymmdd10.),3)
463  and t5.applt_seq_nr &amp;gt; 0
464  group by t6.psn_name, t1.earliest_filing_id
465  order by t6.psn_name, t1.earliest_filing_id
466  ;
NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "not equals".
NOTE: Data file SASDATA.PUBLICATIONSNEW.DATA is in a format that is native to another host, or the
      file encoding does not match the session encoding. Cross Environment Data Access will be
      used, which might require additional CPU resources and might reduce performance.
NOTE: Data file SASDATA.PUBLICATIONSNEW.DATA is in a format that is native to another host, or the
      file encoding does not match the session encoding. Cross Environment Data Access will be
      used, which might require additional CPU resources and might reduce performance.
ERROR: INPUT function requires a character argument.
ERROR: Function YEAR requires a numeric expression as argument 1.
ERROR: Expression using not equals (^=) has components that are of different data types.
ERROR: INPUT function requires a character argument.
ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.
ERROR: INPUT function requires a character argument.
ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.
ERROR: INPUT function requires a character argument.
ERROR: Function INTNX requires a numeric expression as argument 2.
ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.
ERROR: INPUT function requires a character argument.
ERROR: INPUT function requires a character argument.
ERROR: INPUT function requires a character argument.
ERROR: INPUT function requires a character argument.
467
468  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.63 seconds
      cpu time            0.06 seconds


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 10:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470235#M120369</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-06-14T10:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470237#M120371</link>
      <description>&lt;P&gt;You need to do some debugging yourself.&amp;nbsp; The log is telling you what the issue is:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;ERROR: &lt;SPAN class="token keyword"&gt;INPUT&lt;/SPAN&gt; function requires a character argument&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Therefore your variable is numeric, so treat it as numeric (remember I cannot see your data, I can only suggest):&lt;/P&gt;
&lt;PRE&gt;year(t2.Earliest_grant_date_final) &amp;lt;&amp;gt; 9999
and t2.Earliest_grant_date_final &amp;gt;= '01Jan2000'd
and t2.Earliest_grant_date_final &amp;lt;= '31Dec2000'd
and t2b.publn_first_grant=1
and t4.publn_date &amp;lt;= intnx('year',t2.earliest_grant_date_final,3)&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 10:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470237#M120371</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-14T10:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: I</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470244#M120375</link>
      <description>&lt;P&gt;Maxim 3: Know your data.&lt;/P&gt;
&lt;P&gt;Do a proc contents on table Step1.Earlist_grant_date_earlist_id2 and look for the type and display format of earliest_grant_date_final.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 10:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-distinct-values/m-p/470244#M120375</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-14T10:59:17Z</dc:date>
    </item>
  </channel>
</rss>

