<?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 of Building a Complex Query Using In-Line Views in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921181#M362763</link>
    <description>&lt;P&gt;What is it about program B that you don't understand? It is an example of having a main query of employees being joined to a sub-query that is identifying the maximum salaries for each state and job title. The purpose of the query is to report on all employees who are paid the maximum salary within each state and job. title.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2024 19:56:32 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2024-03-20T19:56:32Z</dc:date>
    <item>
      <title>proc sql of Building a Complex Query Using In-Line Views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921123#M362748</link>
      <description>&lt;PRE&gt;a.&lt;BR /&gt;title 'Maximum Salary for Each Job in every State';
proc sql;
select upcase(State) as State, JobTitle, 
       max(Salary) as MaxJobSalary
    from sq.employee
    where State is not null
    group by calculated State, JobTitle
    order by State;
quit;
title;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;b.&lt;BR /&gt;title 'Employees with Highest Salary for their Job in every State';
proc sql;
select detail.EmployeeID, detail.EmployeeName, detail.State, 
       detail.JobTitle, detail.Salary format=dollar12.
    from sq.employee as detail inner join
        (select upcase(State) as State, 
                JobTitle, max(Salary) as MaxJobSalary
             from sq.employee
             where State is not null
             group by calculated State, JobTitle) as summary
    on detail.Jobtitle=summary.JobTitle and
        upcase(detail.State)=Summary.State and
        detail.Salary=Summary.MaxJobSalary
    order by detail.State, detail.JobTitle;
quit;
title;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't easily understand this program can anyone explain this !!!!&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 15:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921123#M362748</guid>
      <dc:creator>Bhagyalakshmi</dc:creator>
      <dc:date>2024-03-20T15:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql of Building a Complex Query Using In-Line Views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921181#M362763</link>
      <description>&lt;P&gt;What is it about program B that you don't understand? It is an example of having a main query of employees being joined to a sub-query that is identifying the maximum salaries for each state and job title. The purpose of the query is to report on all employees who are paid the maximum salary within each state and job. title.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 19:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921181#M362763</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-03-20T19:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql of Building a Complex Query Using In-Line Views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921249#M362791</link>
      <description>&lt;P&gt;Assuming you understand how a inner join works may-be the following helps you to understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume the first SQL creates a view:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table view summary_view as
  select upcase(State) as State, JobTitle, max(Salary) as MaxJobSalary
  from sq.employee
    where State is not null
      group by calculated State, JobTitle
        order by State;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You then could use this view in your 2nd SQL for a join.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select detail.EmployeeID, detail.EmployeeName, detail.State, 
    detail.JobTitle, detail.Salary format=dollar12.
  from 
    sq.employee as detail 
    inner join 
    summary_view as summary
      on detail.Jobtitle=summary.JobTitle and
      upcase(detail.State)=Summary.State and
      detail.Salary=Summary.MaxJobSalary
  order by detail.State, detail.JobTitle;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With an inline view the only difference is that you don't create the view first explicitly but just use the view creation code directly within brackets. It's just about replacing the highlighted view name below with the code that creates the view.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1711000076686.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94828i0C15491F1A77A5A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1711000076686.png" alt="Patrick_0-1711000076686.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select detail.EmployeeID, detail.EmployeeName, detail.State, 
    detail.JobTitle, detail.Salary format=dollar12.
  from 
    sq.employee as detail 
    inner join 
    (
      /* summary_view code */ 
      select upcase(State) as State, JobTitle, max(Salary) as MaxJobSalary
      from sq.employee
      where State is not null
      group by calculated State, JobTitle
    ) as summary
      on detail.Jobtitle=summary.JobTitle and
      upcase(detail.State)=Summary.State and
      detail.Salary=Summary.MaxJobSalary
  order by detail.State, detail.JobTitle;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the inline view the code bit we can skip is the ORDER BY clause as this is only required for returning the final result set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 05:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-of-Building-a-Complex-Query-Using-In-Line-Views/m-p/921249#M362791</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-21T05:51:24Z</dc:date>
    </item>
  </channel>
</rss>

