<?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: Comparing repeated ID variables within a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330509#M271861</link>
    <description>&lt;P&gt;You can't use in a data step a code like:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; SY1314_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'Ineffective'&lt;/SPAN&gt; AND &lt;BR /&gt;   SY1314_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID &lt;SPAN class="token operator"&gt;NOT&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt; SY1415_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID AND ...&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can refer to a variable of current dataset only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tested your &lt;STRONG&gt;sql&lt;/STRONG&gt; code and changed it a little. Try it now:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT &lt;STRONG&gt;COUNT (DISTINCT a.EmployeeID),&lt;/STRONG&gt; 
             a.FiscalYear, 
             b.EmployeeID, 
             b.FiscalYear, 
             c.EmployeeID, 
             c.FiscalYear
FROM SY1314_I AS a, 
     SY1415_I AS b, 
     SY1516_I AS c
WHERE c.EmployeeID 
  NOT IN &lt;STRONG&gt;(SELECT distinct EmployeeID FROM SY1314_I, SY1415_I);&lt;/STRONG&gt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2017 16:22:16 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-02-07T16:22:16Z</dc:date>
    <item>
      <title>Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330502#M271860</link>
      <description>&lt;P&gt;I have a dataset with the following columns:&lt;BR /&gt;FiscalYear, EmployeeID, OverallRating&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find out what employees rated as Ineffective in one FiscalYear are rated in future or previous years. &amp;nbsp;For example, figuing out how to get the count of employees rated Ineffective in 2013 who were then rated anything else in 2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried splitting up the data set by year and rating, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT COUNT (DISTINCT a.EmployeeID), a.FiscalYear, b.EmployeeID, b.FiscalYear, c.EmployeeID, c.FiscalYear
FROM SY1314_I AS a, SY1415_I AS b, SY1516_I AS c
WHERE c.EmployeeID NOT IN (SELECT EmployeeID FROM SY1314_I) AND NOT IN (SELECT EmployeeID FROM SY1415_I);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but end up with some error messages and no result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried breaking up the data by year and rating and comparing it with IF/THEN statements, like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA NotI1415_1516 trash;
	SET SY1314_I SY1415_I SY1516_I;
	IF SY1314_I.EmployeeID = 'Ineffective' AND SY1314_I.EmployeeID NOT IN SY1415_I.EmployeeID AND SY1314.EmployeeID NOT IN SY1516_I.EmployeeID THEN OUTPUT NOTI1415_1516;
ELSE OUTPUT trash;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and also gotten nowhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really not sure what to do, any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 15:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330502#M271860</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-02-07T15:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330509#M271861</link>
      <description>&lt;P&gt;You can't use in a data step a code like:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; SY1314_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'Ineffective'&lt;/SPAN&gt; AND &lt;BR /&gt;   SY1314_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID &lt;SPAN class="token operator"&gt;NOT&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt; SY1415_I&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;EmployeeID AND ...&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can refer to a variable of current dataset only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tested your &lt;STRONG&gt;sql&lt;/STRONG&gt; code and changed it a little. Try it now:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT &lt;STRONG&gt;COUNT (DISTINCT a.EmployeeID),&lt;/STRONG&gt; 
             a.FiscalYear, 
             b.EmployeeID, 
             b.FiscalYear, 
             c.EmployeeID, 
             c.FiscalYear
FROM SY1314_I AS a, 
     SY1415_I AS b, 
     SY1516_I AS c
WHERE c.EmployeeID 
  NOT IN &lt;STRONG&gt;(SELECT distinct EmployeeID FROM SY1314_I, SY1415_I);&lt;/STRONG&gt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 16:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330509#M271861</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-07T16:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330535#M271862</link>
      <description>&lt;P&gt;Thanks for responding! &amp;nbsp;I ran your SQLcode and got "ERROR: Ambiguous reference, column EmployeeID is in more than one table."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried changing it so that it expicitly referenced a.EmployeeID and b.EmployeeID but then got the error that I can't reference 2 columns in a subquery.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330535#M271862</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-02-07T17:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330559#M271863</link>
      <description>&lt;P&gt;I'm confused! You said you have 3 variables, but then you never reference the 3rd one (employee rating) but make one statement that leads one to think that employeeID is a rating.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some example data and what you really want to achieve would definitely help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 18:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330559#M271863</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-07T18:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330616#M271864</link>
      <description>&lt;P&gt;I haven't noticed but there is no logic to select several employeeIDs especially not&amp;nbsp;&lt;/P&gt;
&lt;P&gt;b.employeeID and c.employeeID as you are looking for those that are not there:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT COUNT (DISTINCT a.EmployeeID), 
             a.FiscalYear, 
     /*        &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;b.EmployeeID,&lt;/STRONG&gt;&lt;/FONT&gt;  */
             b.FiscalYear, 
     /*        &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;c.EmployeeID,&lt;/STRONG&gt;&lt;/FONT&gt;  */
             c.FiscalYear
FROM SY1314_I AS a, 
     SY1415_I AS b, 
     SY1516_I AS c
WHERE c.EmployeeID 
  &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;NOT IN&lt;/STRONG&gt;&lt;/FONT&gt; (SELECT distinct EmployeeID FROM SY1314_I, SY1415_I);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Beyond, I think you should relate to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;remarks - and check your logic.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 21:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330616#M271864</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-07T21:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing repeated ID variables within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330754#M271865</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us an example of the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could be as simple as selecting what you want for each year and intersect everything:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table WANT as

select EmployeeID from EMPLOYEES
where RATED eq 'Ineffective' and FiscalYear eq 2013

intersect

select EmployeeID from EMPLOYEES
where FiscalYear ne 2013

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 08:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-repeated-ID-variables-within-a-dataset/m-p/330754#M271865</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-08T08:55:44Z</dc:date>
    </item>
  </channel>
</rss>

