<?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: Selecting with regard to more than one variable in PROC SQL. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64692#M18385</link>
    <description>That doesn't work. My example was for a single identity.&lt;BR /&gt;
&lt;BR /&gt;
If there had been an identity 12 in year 2009 with one or several records where N1 would equal 1, then the two records for identity 11 for year 2009, would also have been selected for the new data set.&lt;BR /&gt;
&lt;BR /&gt;
Both YEAR an ID have significance.</description>
    <pubDate>Thu, 04 Mar 2010 14:05:30 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-03-04T14:05:30Z</dc:date>
    <item>
      <title>Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64690#M18383</link>
      <description>My data set,OldTable, has 6 numeric variables ID (identity number), YEAR, N1-N4.&lt;BR /&gt;
&lt;BR /&gt;
An identity(ID) can have several records each YEAR.&lt;BR /&gt;
&lt;BR /&gt;
In one(1) new data set I want, for each year, an individuals all records if the individual has at least one record, for that year, where the value for N1 equals 1.&lt;BR /&gt;
&lt;BR /&gt;
Ex.(for a single identity)&lt;BR /&gt;
OldTable&lt;BR /&gt;
ID_YEAR_ N1_ N2 _N3_ N4&lt;BR /&gt;
11_2008__0__40__30__90&lt;BR /&gt;
11_2008__1__30__35__50&lt;BR /&gt;
11_2008__1__20__25__60&lt;BR /&gt;
11_2009__0__30__50__95&lt;BR /&gt;
11_2009__0__40__30__60&lt;BR /&gt;
11_2010__1__20__50__40&lt;BR /&gt;
11_2010__0__50__30__50&lt;BR /&gt;
&lt;BR /&gt;
NewTable&lt;BR /&gt;
ID_YEAR_ N1_ N2 _N3_ N4&lt;BR /&gt;
11_2008__0__40__30__90&lt;BR /&gt;
11_2008__1__30__35__50&lt;BR /&gt;
11_2008__1__20__25__60&lt;BR /&gt;
11_2010__1__20__50__40&lt;BR /&gt;
11_2010__0__50__30__50&lt;BR /&gt;
&lt;BR /&gt;
I know how to do it, if I didn't have to regard the different years:&lt;BR /&gt;
&lt;BR /&gt;
select * from oldtable where id in (select distinct id from oldtable where n1=1);&lt;BR /&gt;
&lt;BR /&gt;
If it's possible I would prefer not to use a macro processing different years.</description>
      <pubDate>Thu, 04 Mar 2010 12:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64690#M18383</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-04T12:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64691#M18384</link>
      <description>hi ...  &lt;BR /&gt;
[pre]&lt;BR /&gt;
data old;&lt;BR /&gt;
input ID YEAR  N1-N4;&lt;BR /&gt;
datalines;&lt;BR /&gt;
11 2008  0  40  30  90&lt;BR /&gt;
11 2008  1  30  35  50&lt;BR /&gt;
11 2008  1  20  25  60&lt;BR /&gt;
11 2009  0  30  50  95&lt;BR /&gt;
11 2009  0  40  30  60&lt;BR /&gt;
11 2010  1  20  50  40&lt;BR /&gt;
11 2010  0  50  30  50   &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select * from old &lt;BR /&gt;
where year in (select distinct year from old where n1 eq 1);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=new;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Obs    ID    YEAR    N1    N2    N3    N4&lt;BR /&gt;
 1     11    2008     0    40    30    90&lt;BR /&gt;
 2     11    2008     1    30    35    50&lt;BR /&gt;
 3     11    2008     1    20    25    60&lt;BR /&gt;
 4     11    2010     1    20    50    40&lt;BR /&gt;
 5     11    2010     0    50    30    50&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 04 Mar 2010 13:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64691#M18384</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2010-03-04T13:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64692#M18385</link>
      <description>That doesn't work. My example was for a single identity.&lt;BR /&gt;
&lt;BR /&gt;
If there had been an identity 12 in year 2009 with one or several records where N1 would equal 1, then the two records for identity 11 for year 2009, would also have been selected for the new data set.&lt;BR /&gt;
&lt;BR /&gt;
Both YEAR an ID have significance.</description>
      <pubDate>Thu, 04 Mar 2010 14:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64692#M18385</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-04T14:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64693#M18386</link>
      <description>As recommended at your other post, you may consider using macro code to generate unque SAS data files for each ID and YEAR combination encountered based on your input SAS file.&lt;BR /&gt;
&lt;BR /&gt;
Start with a PROC SQL skeleton program which uses WHERE and selects one ID and YEAR to create a specific-named file.  Then once you get that logic to work as desired, look at creating a SAS macro driven by called macro variable parameters -- these would be DISTINCT combination of ID and YEAR.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=8835" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=8835&lt;/A&gt;</description>
      <pubDate>Thu, 04 Mar 2010 14:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64693#M18386</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-04T14:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64694#M18387</link>
      <description>hi ... OK ... select on ID and YEAR ...&lt;BR /&gt;
[pre]&lt;BR /&gt;
data old;&lt;BR /&gt;
input ID YEAR  N1-N4;&lt;BR /&gt;
datalines;&lt;BR /&gt;
11 2008  0  40  30  90&lt;BR /&gt;
11 2008  1  30  35  50&lt;BR /&gt;
11 2008  1  20  25  60&lt;BR /&gt;
11 2009  0  30  50  95&lt;BR /&gt;
11 2009  0  40  30  60&lt;BR /&gt;
11 2010  1  20  50  40&lt;BR /&gt;
11 2010  0  50  30  50   &lt;BR /&gt;
22 2008  0  40  30  90&lt;BR /&gt;
22 2008  0  30  35  50&lt;BR /&gt;
22 2008  0  20  25  60&lt;BR /&gt;
22 2009  1  30  50  95&lt;BR /&gt;
22 2009  1  40  30  60&lt;BR /&gt;
22 2010  0  20  50  40&lt;BR /&gt;
22 2010  0  50  30  50  &lt;BR /&gt;
33 2001  1  40  30  90&lt;BR /&gt;
33 2001  0  30  35  50&lt;BR /&gt;
33 2001  0  20  25  60&lt;BR /&gt;
33 2004  1  30  50  95&lt;BR /&gt;
33 2004  0  40  30  60&lt;BR /&gt;
33 2005  1  20  50  40&lt;BR /&gt;
33 2005  0  50  30  50    &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
create table new as&lt;BR /&gt;
select * from old &lt;BR /&gt;
where catt(id,year) in (select distinct catt(id,year) from old where n1 eq 1);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=new;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT ...&lt;BR /&gt;
ID=11&lt;BR /&gt;
Obs    YEAR    N1    N2    N3    N4&lt;BR /&gt;
  1    2008     0    40    30    90&lt;BR /&gt;
  2    2008     1    30    35    50&lt;BR /&gt;
  3    2008     1    20    25    60&lt;BR /&gt;
  4    2010     1    20    50    40&lt;BR /&gt;
  5    2010     0    50    30    50&lt;BR /&gt;
&lt;BR /&gt;
ID=22&lt;BR /&gt;
Obs    YEAR    N1    N2    N3    N4&lt;BR /&gt;
  6    2009     1    30    50    95&lt;BR /&gt;
  7    2009     1    40    30    60&lt;BR /&gt;
&lt;BR /&gt;
ID=33&lt;BR /&gt;
Obs    YEAR    N1    N2    N3    N4&lt;BR /&gt;
  8    2001     1    40    30    90&lt;BR /&gt;
  9    2001     0    30    35    50&lt;BR /&gt;
 10    2001     0    20    25    60&lt;BR /&gt;
 11    2004     1    30    50    95&lt;BR /&gt;
 12    2004     0    40    30    60&lt;BR /&gt;
 13    2005     1    20    50    40&lt;BR /&gt;
 14    2005     0    50    30    50&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 04 Mar 2010 14:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64694#M18387</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2010-03-04T14:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting with regard to more than one variable in PROC SQL.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64695#M18388</link>
      <description>Thank you. Nice solution. I should have figured it out by myself.</description>
      <pubDate>Thu, 04 Mar 2010 14:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-with-regard-to-more-than-one-variable-in-PROC-SQL/m-p/64695#M18388</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-04T14:35:45Z</dc:date>
    </item>
  </channel>
</rss>

