<?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: PROC SQL Subqueries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716248#M221322</link>
    <description>&lt;P&gt;and you should replace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATS(firstname||" "||lastname)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CATX(" ", firstname, lastname)&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2021 22:41:57 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2021-02-02T22:41:57Z</dc:date>
    <item>
      <title>PROC SQL Subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716237#M221316</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have a table consisting of a list of females and males as follows:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anita_n_0-1612302355318.png" style="width: 333px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54248iBD2CA31018A49A52/image-dimensions/333x128?v=v2" width="333" height="128" role="button" title="Anita_n_0-1612302355318.png" alt="Anita_n_0-1612302355318.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I wish to use the below subquery to get out the first and last name in one column for&lt;/P&gt;
&lt;P&gt;for the female with the minimum age. But am not getting it working. I will appreciate&lt;/P&gt;
&lt;P&gt;any help. Thanks&lt;/P&gt;
&lt;P&gt;this code works fine for the minimum age for both sex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE age=(SELECT MIN(age) FROM mytable) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;but I want to add to this code, that the minimum age should not apply to both sex but only the females.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE sex= "female" AND age=(SELECT MIN(age) FROM mytable) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if I add this part with sex="female" I get no results&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 21:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716237#M221316</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-02T21:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716240#M221318</link>
      <description>&lt;P&gt;Does this work for you? Your previous query was checking for women with the smallest age - but the smallest age was from the whole population which may not exist, therefore you get no records returned.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE sex= "female" AND age=(SELECT MIN(age) FROM mytable where sex='female') ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you have to use a subquery? A HAVING clause is easier to code and understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE sex= "female" 
having age=min(age) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have a table consisting of a list of females and males as follows:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anita_n_0-1612302355318.png" style="width: 333px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54248iBD2CA31018A49A52/image-dimensions/333x128?v=v2" width="333" height="128" role="button" title="Anita_n_0-1612302355318.png" alt="Anita_n_0-1612302355318.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I wish to use the below subquery to get out the first and last name in one column for&lt;/P&gt;
&lt;P&gt;for the female with the minimum age. But am not getting it working. I will appreciate&lt;/P&gt;
&lt;P&gt;any help. Thanks&lt;/P&gt;
&lt;P&gt;this code works fine for the minimum age for both sex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE age=(SELECT MIN(age) FROM mytable) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;but I want to add to this code, that the minimum age should not apply to both sex but only the females.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT lastname,firstname, age,
CATS(firstname||" "||lastname) AS Name FROM mytable
WHERE sex= "female" AND age=(SELECT MIN(age) FROM mytable) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if I add this part with sex="female" I get no results&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 22:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716240#M221318</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-02T22:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716241#M221319</link>
      <description>Okay thanks for the quick reply, I need to test that. I will leave a feedback</description>
      <pubDate>Tue, 02 Feb 2021 22:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716241#M221319</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-02T22:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716248#M221322</link>
      <description>&lt;P&gt;and you should replace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATS(firstname||" "||lastname)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CATX(" ", firstname, lastname)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 22:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716248#M221322</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-02-02T22:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716333#M221360</link>
      <description>Thanks, it worked fine</description>
      <pubDate>Wed, 03 Feb 2021 07:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Subqueries/m-p/716333#M221360</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-03T07:55:43Z</dc:date>
    </item>
  </channel>
</rss>

