<?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: How to create a macro variable to subset a dataset in Proc SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726423#M225706</link>
    <description>&lt;P&gt;Hello. Athenkosi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because I have to satisfy what the instructor wants.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a Macro variable for Dallas in the Location variable of Data ALL.&lt;BR /&gt;Use this macro variable to subset the ‘ALL’ excel data inside the proc SQL to select variables student_name,&lt;BR /&gt;teacher, fee, days, paid, location. Write a Proc SQL query to find the ‘average fee’ and ‘total fee’&lt;BR /&gt;by ‘paid’ variable for Dallas.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 15:11:22 GMT</pubDate>
    <dc:creator>xtan2</dc:creator>
    <dc:date>2021-03-15T15:11:22Z</dc:date>
    <item>
      <title>How to create a macro variable to subset a dataset in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726384#M225696</link>
      <description>&lt;P&gt;There is a question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a Macro variable for Dallas in the Location variable of Data: ALL.&lt;BR /&gt;Use this macro variable to subset the ‘ALL’ excel data inside the proc SQL to select variables student_name,&lt;BR /&gt;teacher, fee, days, paid, location. Write a Proc SQL query to find the ‘average fee’ and ‘total fee’&lt;BR /&gt;by ‘paid’ variable for Dallas.&lt;/P&gt;&lt;P&gt;This data set of All is like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xtan2_1-1615816973947.png" style="width: 807px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55955iD5C2FF70F3444F39/image-dimensions/807x343?v=v2" width="807" height="343" role="button" title="xtan2_1-1615816973947.png" alt="xtan2_1-1615816973947.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Using this following Proc SQL procedure the goal is easily achieved:&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;Select student_name, fee, days, paid, location,&lt;BR /&gt;mean(fee) as avg_fee label = 'average fee',&lt;BR /&gt;sum(fee) as tot_fee label = 'total fee'&lt;BR /&gt;From All&lt;BR /&gt;Where location = 'Dallas' and Paid = 'Y';&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xtan2_2-1615817163543.png" style="width: 490px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55956i0D68BA2854A7CB1B/image-dimensions/490x448?v=v2" width="490" height="448" role="button" title="xtan2_2-1615817163543.png" alt="xtan2_2-1615817163543.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, when I tried to use the following code to create a macro variable to subset the location variable into 'Dallas', it did not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;Select student_name, fee, days, paid,&lt;BR /&gt;mean(fee) as avg_fee label = 'average fee',&lt;BR /&gt;sum(fee) as tot_fee label = 'total fee', location into :Dallas&lt;BR /&gt;From All&lt;BR /&gt;Where Paid = 'Y';&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xtan2_3-1615817289752.png" style="width: 507px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55957iBFF2CA38B4131A5A/image-dimensions/507x442?v=v2" width="507" height="442" role="button" title="xtan2_3-1615817289752.png" alt="xtan2_3-1615817289752.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Would someone like to kindly show me how I should create the macro variable so as to subset the location variable successfully?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726384#M225696</guid>
      <dc:creator>xtan2</dc:creator>
      <dc:date>2021-03-15T14:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable to subset a dataset in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726412#M225702</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you want to create a macro variable if you know you want to filter by Dallas?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726412#M225702</guid>
      <dc:creator>Athenkosi</dc:creator>
      <dc:date>2021-03-15T14:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable to subset a dataset in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726423#M225706</link>
      <description>&lt;P&gt;Hello. Athenkosi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because I have to satisfy what the instructor wants.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a Macro variable for Dallas in the Location variable of Data ALL.&lt;BR /&gt;Use this macro variable to subset the ‘ALL’ excel data inside the proc SQL to select variables student_name,&lt;BR /&gt;teacher, fee, days, paid, location. Write a Proc SQL query to find the ‘average fee’ and ‘total fee’&lt;BR /&gt;by ‘paid’ variable for Dallas.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 15:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726423#M225706</guid>
      <dc:creator>xtan2</dc:creator>
      <dc:date>2021-03-15T15:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable to subset a dataset in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726436#M225715</link>
      <description>&lt;P&gt;&amp;nbsp;I got it! Also, I correct a mistake:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set should be classified by 'Pait', not 'Paid' = 'Y'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let loctn = Dallas;&lt;BR /&gt;Proc SQL;&lt;BR /&gt;Select student_name, fee, days, paid, location,&lt;BR /&gt;mean(fee) as avg_fee label = 'average fee',&lt;BR /&gt;sum(fee) as tot_fee label = 'total fee'&lt;BR /&gt;From All&lt;BR /&gt;Where location = "&amp;amp;loctn"&lt;BR /&gt;Group by paid;&lt;BR /&gt;Quit;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 15:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-to-subset-a-dataset-in-Proc-SQL/m-p/726436#M225715</guid>
      <dc:creator>xtan2</dc:creator>
      <dc:date>2021-03-15T15:46:48Z</dc:date>
    </item>
  </channel>
</rss>

