<?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: Macro Function Invoking using SQL Table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298573#M20347</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, its very difficult to read that code with no formatting and all upper case. &amp;nbsp;What is it your trying to accomplish. &amp;nbsp;Post some simple test data (in the form of a datastep), and what the output should look like. &amp;nbsp;You can "conditionally" execute code by using call execute:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.class;
  call execute(cats('%some_macro (',age,');'));
run;&lt;/PRE&gt;
&lt;P&gt;This will call %some_macro for each observation in sashelp.class for instance. &amp;nbsp;However most of the code you provide seems redundant, hence why I want to see start and end position, there will be far easier and better ways of doing it.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2016 09:21:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-09-15T09:21:05Z</dc:date>
    <item>
      <title>Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298569#M20343</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to invoke the macro function dynamically using the data from SQL table &amp;nbsp;but i am not sure why the last part of my code is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let start_date = '31Mar2008'd;&lt;BR /&gt;%let end_date = '30Apr2008'd;&lt;/P&gt;&lt;P&gt;DATA work.TMP_1;&lt;BR /&gt;FORMAT start_dt DATETIME.;&lt;BR /&gt;FORMAT end_dt DATETIME.;&lt;BR /&gt;FORMAT stdt DATE9.;&lt;BR /&gt;start_dt=DHMS(&amp;amp;start_date,0,0,0);&lt;BR /&gt;end_dt= DHMS(&amp;amp;end_date,0,0,0);&lt;BR /&gt;date_dif = intck('month',datepart(start_dt), datepart(end_dt));&lt;BR /&gt;/* stdt = intnx('month',datepart(start_dt),1,'same');*/&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT&lt;BR /&gt;date_dif INTO: COUNT_VAR&lt;BR /&gt;FROM WORK.TMP_1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%LET COUNT_VAR=%TRIM(&amp;amp;COUNT_VAR.);&lt;BR /&gt;%PUT &amp;amp;COUNT_VAR.;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;DROP TABLE work.TMP2;&lt;BR /&gt;CREATE TABLE work.TMP2&lt;BR /&gt;(&lt;BR /&gt;date NUM FORMAT = DATE9.);&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%MACRO test (COUNT_VAR=);&lt;BR /&gt;%DO I=0 %TO &amp;amp;COUNT_VAR.;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;INSERT INTO tmp2&lt;BR /&gt;SELECT intnx('month',datepart(start_dt),&amp;amp;i,'same') AS date FORMAT=DATE9.&lt;BR /&gt;FROM TMP_1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;%END;&lt;BR /&gt;%MEND DEFAULT_12_MONTH;&lt;/P&gt;&lt;P&gt;OPTIONS MPRINT;&lt;BR /&gt;%test(COUNT_VAR=&amp;amp;COUNT_VAR.);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data tmp2;&lt;BR /&gt;set tmp2;&lt;BR /&gt;format cohort DATETIME.;&lt;BR /&gt;cohort = DHMS(date,0,0,0);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;create table cohort_table as&lt;BR /&gt;select&lt;BR /&gt;'12' as period ,&lt;BR /&gt;INPUT(PUT(DATEPART(cohort),YYMMN6.), Z6.) AS start_date&lt;BR /&gt;from tmp2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT start_date INTO&lt;BR /&gt;:ST_DT_1 - :ST_DT_%eval(&amp;amp;COUNT_VAR.+1)&lt;BR /&gt;FROM cohort_table;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;%put &amp;amp;st_dt_1.;&lt;/P&gt;&lt;P&gt;%macro myprep(period,start_date);&lt;BR /&gt;%put &amp;amp;period;&lt;BR /&gt;%put &amp;amp;start_date;&lt;/P&gt;&lt;P&gt;%mend myprep;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;DO j = 1 to &amp;amp;count_var.;&lt;BR /&gt;%myprep(12,&amp;amp;st_dt_j);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298569#M20343</guid>
      <dc:creator>akshaybatra1</dc:creator>
      <dc:date>2016-09-15T09:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298572#M20346</link>
      <description>&lt;P&gt;When trying to call/execute a macro from a data step use DOSUBL() or CALL EXECUTE().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation has good examples on usage.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298572#M20346</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T09:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298573#M20347</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, its very difficult to read that code with no formatting and all upper case. &amp;nbsp;What is it your trying to accomplish. &amp;nbsp;Post some simple test data (in the form of a datastep), and what the output should look like. &amp;nbsp;You can "conditionally" execute code by using call execute:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.class;
  call execute(cats('%some_macro (',age,');'));
run;&lt;/PRE&gt;
&lt;P&gt;This will call %some_macro for each observation in sashelp.class for instance. &amp;nbsp;However most of the code you provide seems redundant, hence why I want to see start and end position, there will be far easier and better ways of doing it.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298573#M20347</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-15T09:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298574#M20348</link>
      <description>&lt;P&gt;Thanks for your reply,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;call execute('%myprep(period'||period||',start_date'||start_date||');');&lt;BR /&gt;&amp;nbsp;call execute('%nrstr(%myprep('||period||','||start_date||'))');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesnt work aswell.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298574#M20348</guid>
      <dc:creator>akshaybatra1</dc:creator>
      <dc:date>2016-09-15T09:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298576#M20350</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/104733"&gt;@akshaybatra1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute('%myprep(period'||period||',start_date'||start_date||');');&lt;BR /&gt;&amp;nbsp;call execute('%nrstr(%myprep('||period||','||start_date||'))');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it doesnt work aswell.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you did it incorrectly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generate the macro command as a string variable first - make sure it's valid SAS code and then pass that string to call execute.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298576#M20350</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T09:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298577#M20351</link>
      <description>&lt;P&gt;if you run the code in SAS , except the macro, it will give you a table COHORT_TABLE. this &amp;nbsp;has&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Period &amp;nbsp;Start_date&lt;/P&gt;&lt;P&gt;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200803&lt;BR /&gt;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200804&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to pass these parameters into macro function dynamically.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298577#M20351</guid>
      <dc:creator>akshaybatra1</dc:creator>
      <dc:date>2016-09-15T09:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298581#M20354</link>
      <description>&lt;P&gt;Yes, but the question is why do you need to pass data into macro? &amp;nbsp;Macro language is a text based pre-compilation text generator - it does not do any processing, nor does it have datatypes/structures for processing data, that is what Base SAS is for. &amp;nbsp;It sounds like you are trying to emulate functionality already within Base SAS in Macro Language, which is never a good thing. &amp;nbsp;If you post what you are doing with that data, there will be a better method, either merging, re-structuring data etc.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298581#M20354</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-15T09:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298586#M20355</link>
      <description>&lt;P&gt;I have a macro&amp;nbsp;%myprep(period, start_date) where we need to pass parameters for every cohort, so ideally users have to write in the program &amp;nbsp;multiple times, as below.&lt;/P&gt;&lt;P&gt;%myprep(12,'201012')&lt;BR /&gt;%myprep(12,'201101')&lt;BR /&gt;%myprep(12,'201102')&lt;BR /&gt;%myprep(12,'201103')&lt;BR /&gt;%myprep(12,'201104')&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My program creates a SQL table&amp;nbsp;&lt;/P&gt;&lt;P&gt;period &amp;nbsp; &amp;nbsp; Start_date&lt;/P&gt;&lt;P&gt;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;201012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;201101&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;201102&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;I would like to use this table and pass it into function %myprep(period, start_date) so that we dont need to invoke macro function multiple times.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298586#M20355</guid>
      <dc:creator>akshaybatra1</dc:creator>
      <dc:date>2016-09-15T09:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298587#M20356</link>
      <description>&lt;P&gt;Why doesn't your macro loop to do the insert based on start and end date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a table driven macro call execute is correct. As I stated before generate the string variable and pass that to call execute.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For starters Your previous attempt had the words period and start date when those are not in your macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Umtested but easy to debug&lt;/P&gt;
&lt;P&gt;Str= catt('%myprep(, period, ',', quote(start_date), ');');&lt;/P&gt;
&lt;P&gt;call execute(Str);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;steing needs to match macro call shown earlier, quotes included.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298587#M20356</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T09:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298596#M20358</link>
      <description>&lt;P&gt;It helps when you are consistent in the way you hand over parameters to macros&lt;/P&gt;
&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%myprep(12,'201012')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will complicate your work unnecessarily&lt;/P&gt;
&lt;P&gt;Change your macro so that the (double) quotes are placed around the string where necessary, so you can write the string raw without quotes into the macro call. That also makes calling it with call execute easier.&lt;/P&gt;
&lt;P&gt;Next, contemplate if it would not be better to use real SAS data values when you are dealing with what is basically a date. Within that context, SAS dates can be stored in macro variables with their raw numerical values (days from 01jan1960), which also makes quoting unnecessary.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 10:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298596#M20358</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-15T10:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Function Invoking using SQL Table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298606#M20361</link>
      <description>&lt;P&gt;Super !! It works, i just changed it in a way i need it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro myprep(period,start_date);&lt;BR /&gt;%put &amp;amp;period;&lt;BR /&gt;%put &amp;amp;start_date;&lt;BR /&gt;run;&lt;BR /&gt;%mend myprep;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set cohort_table;&lt;BR /&gt;Str= catt('%myprep(',12, ',',start_date, ');');&lt;BR /&gt;call execute(Str);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 11:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-Function-Invoking-using-SQL-Table/m-p/298606#M20361</guid>
      <dc:creator>akshaybatra1</dc:creator>
      <dc:date>2016-09-15T11:26:01Z</dc:date>
    </item>
  </channel>
</rss>

