<?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: New to Macros! Need Help! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785496#M250688</link>
    <description>&lt;P&gt;&lt;A href="https://www.google.com/search?q=%40sas.com+%25eval()" target="_blank"&gt;https://www.google.com/search?q=%40sas.com+%25eval()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n07pr39df9k7m3n1w3x1q09iewta.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n07pr39df9k7m3n1w3x1q09iewta.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Dec 2021 02:16:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-12-11T02:16:53Z</dc:date>
    <item>
      <title>New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785485#M250684</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a macro that adds a variable equal to one to a dataset, and then sum the counts of that variable and merges it to another dataset. I need to do this for datasets corresponding to the years 2004 through 2018. The structure of the data set names are "rp_equities_2004", "rp_equities_2005"...etc. I have attached code to this message with what I currently have. I know it is not correct but I was hoping someone could point me in the right direction. It's difficult because the files I am working with are massive, so simply running a check is difficult to do. Here is my current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro raven;&lt;BR /&gt;%do i = 2004 %to 2018;&lt;/P&gt;&lt;P&gt;data rp_equities_i; set rp_equities_i;&lt;BR /&gt;article = 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table media_cov_i as select distinct&lt;BR /&gt;a.*, b.count(article) as article_count_rel&lt;BR /&gt;from media_cov_(i-1) as a left join rp_equities_i as b&lt;BR /&gt;on a.rp_entity_id = b.rp_entity_id and a.datadate &amp;lt;= b.rpna_date_utc &amp;lt;= b.datadate_lead and b.relevence &amp;gt; 75;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785485#M250684</guid>
      <dc:creator>Chutzler</dc:creator>
      <dc:date>2021-12-10T23:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785486#M250685</link>
      <description>&lt;P&gt;You set up a loop, with the macro variable i, but then you never reference this macro variable after that — you would reference it as &amp;amp;i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, your final %END needs a semi-colon after it. Also, you have to end a macro with %MEND; and you then need to call the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So with that in mind, here is my attempt to fix what you did (there may be other errors not described above)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro raven;
    %do i = 2004 %to 2018;
        data rp_equities_&amp;amp;i; 
            set rp_equities_&amp;amp;i;
            article = 1;
        run;
        proc sql;
             create table media_cov_&amp;amp;i as select distinct
             a.*, count(b.article) as article_count_rel
             from media_cov_%eval(&amp;amp;i-1) as a left join rp_equities_&amp;amp;i as b
             on a.rp_entity_id = b.rp_entity_id and a.datadate &amp;lt;= b.rpna_date_utc &amp;lt;= b.datadate_lead
             and b.relevence &amp;gt; 75;
        quit;
    %end;
%mend;
%raven&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 00:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785486#M250685</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-11T00:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785490#M250686</link>
      <description>&lt;P&gt;Thanks for the help! Quick question-- what does the %eval do?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 01:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785490#M250686</guid>
      <dc:creator>Chutzler</dc:creator>
      <dc:date>2021-12-11T01:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785496#M250688</link>
      <description>&lt;P&gt;&lt;A href="https://www.google.com/search?q=%40sas.com+%25eval()" target="_blank"&gt;https://www.google.com/search?q=%40sas.com+%25eval()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n07pr39df9k7m3n1w3x1q09iewta.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n07pr39df9k7m3n1w3x1q09iewta.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 02:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785496#M250688</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-11T02:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785500#M250690</link>
      <description>Why are you adding article=1, is that just for summing/counting?&lt;BR /&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785500#M250690</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-11T03:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: New to Macros! Need Help!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785504#M250691</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;It's difficult because the files I am working with are massive, so simply running a check is difficult to do.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;SAS has a nifty option - OBS= that allows you&amp;nbsp;to set how many observations it processes and you can use that for testing. Set it to a smaller number for testing and&amp;nbsp;when ready to run, set it to max.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example (CLASS has 19 records).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option obs=5;
proc means data=sashelp.class;
run;

option obs=max;
proc means data=sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;U&gt;&lt;STRONG&gt;However&lt;/STRONG&gt;&lt;/U&gt;, if you code using this style you cannot&amp;nbsp;use this option as it will&amp;nbsp;replace your original data set. This is one of the reasons this type of coding isn't recommended.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rp_equities_i; set rp_equities_i;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/406306"&gt;@Chutzler&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create a macro that adds a variable equal to one to a dataset, and then sum the counts of that variable and merges it to another dataset. I need to do this for datasets corresponding to the years 2004 through 2018. The structure of the data set names are "rp_equities_2004", "rp_equities_2005"...etc. I have attached code to this message with what I currently have. I know it is not correct but I was hoping someone could point me in the right direction. It's difficult because the files I am working with are massive, so simply running a check is difficult to do. Here is my current code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro raven;&lt;BR /&gt;%do i = 2004 %to 2018;&lt;/P&gt;
&lt;P&gt;data rp_equities_i; set rp_equities_i;&lt;BR /&gt;article = 1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table media_cov_i as select distinct&lt;BR /&gt;a.*, b.count(article) as article_count_rel&lt;BR /&gt;from media_cov_(i-1) as a left join rp_equities_i as b&lt;BR /&gt;on a.rp_entity_id = b.rp_entity_id and a.datadate &amp;lt;= b.rpna_date_utc &amp;lt;= b.datadate_lead and b.relevence &amp;gt; 75;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-to-Macros-Need-Help/m-p/785504#M250691</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-11T03:41:10Z</dc:date>
    </item>
  </channel>
</rss>

