<?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: Creating a macro with proc sql. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709439#M218156</link>
    <description>&lt;P&gt;You are asking to extract and sum "&lt;SPAN&gt;games for a &lt;STRONG&gt;specific year&lt;/STRONG&gt; and &lt;STRONG&gt;specific platform&lt;/STRONG&gt; and sum up sales".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To extract specific info use&amp;nbsp;&lt;STRONG&gt;where.&lt;/STRONG&gt; Your macro should look like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO sorting(Year, Platform);
proc sql;
create table want4 as
select Name,Platform, Year, 
       sum(NA_Sales, JP_Sales, Other_Sales) as suma
from games (where=(Year=&amp;amp;year and Platform=&amp;amp;palatform))
group by Year, Platform /* probably not needed as one group selected */
order by calculated suma;  /* desc ?? you did not select this variable */
quit;
run;
%mend;
%sorting(2010,"PS3")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jan 2021 15:31:40 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-01-05T15:31:40Z</dc:date>
    <item>
      <title>Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709426#M218145</link>
      <description>&lt;P&gt;Hello. I'm new to the forum.&lt;/P&gt;&lt;P&gt;I want to create a macro, that for the following data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pawel__0-1609857256873.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53218i68B2F53B2DDAA74A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Pawel__0-1609857256873.png" alt="Pawel__0-1609857256873.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;will display all games for a specific year and specific platform and sum up sales.&lt;/P&gt;&lt;P&gt;My idea was this, but unfortunately it doesn't work.&lt;/P&gt;&lt;PRE&gt;%MACRO sorting(Year, Platform);
proc sql;
create table want4 as
select Name,Platform, Year, sum(NA_Sales, JP_Sales, Other_Sales) as suma
from games
group by &amp;amp;Year, &amp;amp;Platform
order by suma desc;
quit;
run;
%mend;
%sorting(2010,"PS3")&lt;/PRE&gt;&lt;P&gt;Is it possible for the result to be a table?&lt;/P&gt;&lt;P&gt;I suppose I'm passing the arguments incorrectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 14:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709426#M218145</guid>
      <dc:creator>Pawel_</dc:creator>
      <dc:date>2021-01-05T14:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709429#M218147</link>
      <description>&lt;P&gt;Why do you need a macro at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SUMMARY or PROC REPORT or PROC TABULATE or PROC SQL will do this without macros.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709429#M218147</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-05T15:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709430#M218148</link>
      <description>I know, but I have to use macro.</description>
      <pubDate>Tue, 05 Jan 2021 15:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709430#M218148</guid>
      <dc:creator>Pawel_</dc:creator>
      <dc:date>2021-01-05T15:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709431#M218149</link>
      <description>&lt;P&gt;Turn on the MPRINT option before calling your macro so that you can see what SAS code it is generating.&lt;/P&gt;
&lt;P&gt;Currently it is generating this code, which does not make any sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want4 as
select Name,Platform, Year, sum(NA_Sales, JP_Sales, Other_Sales) as suma
from games
group by 2010, "PS3"
order by suma desc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to create the new variable SUMA then just use a data step (you could use PROC SQL also but why?).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want4 ;
  set games;
  suma = sum(NA_Sales, JP_Sales, Other_Sales) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709431#M218149</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-05T15:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709432#M218150</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362768"&gt;@Pawel_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I know, but I have to use macro.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;????&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709432#M218150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-05T15:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709433#M218151</link>
      <description>&lt;P&gt;Default macro, gets the answers while using a macro (pointlessly, but a macro is used)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO sorting;
proc sql;
create table want4 as
select Name,Platform, Year, sum(NA_Sales, JP_Sales, Other_Sales) as suma
from games
group by Year, Platform
order by suma desc;
quit;
run;
%mend;
%sorting&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Didn't someone explain what the macro is supposed to do? Macros make code dynamic, what part of the above should be dynamic?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709433#M218151</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-05T15:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709437#M218155</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362768"&gt;@Pawel_&lt;/a&gt;&amp;nbsp;wrote (emphasis mine)::&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;will display all games for a &lt;EM&gt;&lt;STRONG&gt;specific&lt;/STRONG&gt;&lt;/EM&gt; year and &lt;EM&gt;&lt;STRONG&gt;specific&lt;/STRONG&gt;&lt;/EM&gt; platform and sum up sales.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If by "specific" you mean a single user-specified year and platform, then you would need a "where" clause, not a "group by".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I don't know what you mean by "Is it possible for the result to be a table?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally, I reply with the most common observation on this forum.&amp;nbsp; Allow me to be recursive:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A problem description that just says "it doesn't work" doesn't work.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709437#M218155</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-05T15:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro with proc sql.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709439#M218156</link>
      <description>&lt;P&gt;You are asking to extract and sum "&lt;SPAN&gt;games for a &lt;STRONG&gt;specific year&lt;/STRONG&gt; and &lt;STRONG&gt;specific platform&lt;/STRONG&gt; and sum up sales".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To extract specific info use&amp;nbsp;&lt;STRONG&gt;where.&lt;/STRONG&gt; Your macro should look like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO sorting(Year, Platform);
proc sql;
create table want4 as
select Name,Platform, Year, 
       sum(NA_Sales, JP_Sales, Other_Sales) as suma
from games (where=(Year=&amp;amp;year and Platform=&amp;amp;palatform))
group by Year, Platform /* probably not needed as one group selected */
order by calculated suma;  /* desc ?? you did not select this variable */
quit;
run;
%mend;
%sorting(2010,"PS3")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 15:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-with-proc-sql/m-p/709439#M218156</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-05T15:31:40Z</dc:date>
    </item>
  </channel>
</rss>

