<?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 %Macro is not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480821#M286666</link>
    <description>&lt;P&gt;I am trying to run the macro below and generate the records I need based on the prompt selections in SAS Enterprise Guide.&amp;nbsp; All of the macros used within the code below are prompt the user would fill in prior to the code executing.&amp;nbsp; The prompt &amp;amp;disp_records requires the selection of a single value from a list, and all of the other date prompts are manually entered in the format that is required.&amp;nbsp; when I run the macro, no errors are produced.&amp;nbsp; When I run the PROC SQL after the macro,&amp;nbsp;it says work.test_records does not exist.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wanting the macro to run based on the &amp;amp;disp_records prompt.&amp;nbsp; the the Proc SQL will add a few more parameters that are common regardless of the &amp;amp;disp_records prompt selection.&amp;nbsp; Those records should produce the new table "work.results".&amp;nbsp; I am probably missing something extremely simple.&amp;nbsp; Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro records();&lt;BR /&gt;&amp;nbsp; %if &amp;amp;disp_records = 1 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where infodate1 ge infodate2;&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; %else %if &amp;amp;disp_records = 2 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where substr(end_date_ts,1,10) = '2222-12-31';&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; %else %if &amp;amp;disp_records = 3 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where date_ts ge &amp;amp;date_ts_min;&lt;BR /&gt;&amp;nbsp;and date_ts le &amp;amp;date_ts_max;&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend records();&lt;/P&gt;&lt;P&gt;%records();&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE WORK.results AS&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SELECT *&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM work.test_records&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE(%_eg_WhereParam( (source), match_source, IN, TYPE=S, IS_EXPLICIT=0 )&lt;BR /&gt;&amp;nbsp;&amp;nbsp; AND %_eg_WhereParam( (data_date), data_date_min, BETWEEN, TYPE=D, MAX=data_date_max, IS_EXPLICIT=0 ));&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jul 2018 14:59:50 GMT</pubDate>
    <dc:creator>anballa</dc:creator>
    <dc:date>2018-07-24T14:59:50Z</dc:date>
    <item>
      <title>%Macro is not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480821#M286666</link>
      <description>&lt;P&gt;I am trying to run the macro below and generate the records I need based on the prompt selections in SAS Enterprise Guide.&amp;nbsp; All of the macros used within the code below are prompt the user would fill in prior to the code executing.&amp;nbsp; The prompt &amp;amp;disp_records requires the selection of a single value from a list, and all of the other date prompts are manually entered in the format that is required.&amp;nbsp; when I run the macro, no errors are produced.&amp;nbsp; When I run the PROC SQL after the macro,&amp;nbsp;it says work.test_records does not exist.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wanting the macro to run based on the &amp;amp;disp_records prompt.&amp;nbsp; the the Proc SQL will add a few more parameters that are common regardless of the &amp;amp;disp_records prompt selection.&amp;nbsp; Those records should produce the new table "work.results".&amp;nbsp; I am probably missing something extremely simple.&amp;nbsp; Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro records();&lt;BR /&gt;&amp;nbsp; %if &amp;amp;disp_records = 1 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where infodate1 ge infodate2;&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; %else %if &amp;amp;disp_records = 2 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where substr(end_date_ts,1,10) = '2222-12-31';&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; %else %if &amp;amp;disp_records = 3 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data work.test_records;&lt;BR /&gt;&amp;nbsp;set library1.table;&lt;BR /&gt;&amp;nbsp;where date_ts ge &amp;amp;date_ts_min;&lt;BR /&gt;&amp;nbsp;and date_ts le &amp;amp;date_ts_max;&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend records();&lt;/P&gt;&lt;P&gt;%records();&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE WORK.results AS&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SELECT *&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM work.test_records&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE(%_eg_WhereParam( (source), match_source, IN, TYPE=S, IS_EXPLICIT=0 )&lt;BR /&gt;&amp;nbsp;&amp;nbsp; AND %_eg_WhereParam( (data_date), data_date_min, BETWEEN, TYPE=D, MAX=data_date_max, IS_EXPLICIT=0 ));&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 14:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480821#M286666</guid>
      <dc:creator>anballa</dc:creator>
      <dc:date>2018-07-24T14:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: %Macro is not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480837#M286667</link>
      <description>&lt;P&gt;Set&lt;/P&gt;
&lt;P&gt;options mprint symbolgen mlogic;&lt;/P&gt;
&lt;P&gt;before the step where you execute the macro.&lt;/P&gt;
&lt;P&gt;and run the code to show in the log the code generated, the values of created/manipulated macro variables and the results of macro logic statements (%if %do and such). Copy and paste&amp;nbsp;the log results in a code box using the forums {i} icon.&lt;/P&gt;
&lt;P&gt;The options will also place any notes such as 0 records were selected or such in a better context than you may be getting now.&lt;/P&gt;
&lt;P&gt;Turn off the options with&lt;/P&gt;
&lt;P&gt;options nomprint nosymbolgen nomlogic;&lt;/P&gt;
&lt;P&gt;after the macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possibility is that your macro variable &amp;amp;disp_records&amp;nbsp;has a value other than 1, 2 or 3.&lt;/P&gt;
&lt;P&gt;Or if &amp;amp;disp_records&amp;nbsp;=1 then none of the values meet the condition where infodate1 ge infodate2; for library1.table or similar that the where statements don't have any records for the other &amp;amp;disp_records values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note SAS would allow using&lt;/P&gt;
&lt;P&gt;where &amp;amp;date_ts_min le date_ts&amp;nbsp;&amp;nbsp;le &amp;amp;date_ts_max;&lt;/P&gt;
&lt;P&gt;which may be easier to recognize/ read the code when memory gets a bit stale then the "and".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless you are going to add data manipulation that is unique to each &amp;amp;disp_records value you might consider something similar to :&lt;/P&gt;
&lt;PRE&gt;%macro records();
  data work.test_records;
    set library1.table;

  %if &amp;amp;disp_records = 1 %then
    %do;
      where infodate1 ge infodate2;
    %end;
  %else %if &amp;amp;disp_records = 2 %then
    %do;
      where substr(end_date_ts,1,10) = '2222-12-31';
    %end;
  %else %if &amp;amp;disp_records = 3 %then
    %do;
       where date_ts ge &amp;amp;date_ts_min;
       and date_ts le &amp;amp;date_ts_max;
    %end;
 run;

%mend records();&lt;/PRE&gt;
&lt;P&gt;to emphasize that the purpose of the &amp;amp;disp_records is to set where clause. Also if none of the where clause are selected then work.test_records would be the entire contents of library1.table. Which may mitigate the empty or missing work.test_records issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 15:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480837#M286667</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-24T15:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: %Macro is not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480843#M286668</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;'s suggested rewrite is good under normal circumstances, but could hide the problem here.&amp;nbsp; If the problem is that &amp;amp;DISP_RECORDS is actually 5, your original program will generate the error that you mentioned.&amp;nbsp; But this rewrite will create the output data set (with no subsetting applied).&amp;nbsp; Until the program&amp;nbsp; is debugged, you could start out by temporarily adding this as the first statement within your macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put DISP_RECORDS is &amp;amp;disp_records;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other suggestions, such as temporarily turning on MPRINT, are excellent.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 15:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-is-not-working/m-p/480843#M286668</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-24T15:47:03Z</dc:date>
    </item>
  </channel>
</rss>

