<?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: Using Proc SQL to write a simple macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454062#M284153</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am learning how to write macros in SAS and practice the same. While I understand this can be done with inbuilt functions, it was my attempt to try and learn and practice developing macros. Appreciate the insight.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Apr 2018 20:53:28 GMT</pubDate>
    <dc:creator>UdayGuntupalli</dc:creator>
    <dc:date>2018-04-13T20:53:28Z</dc:date>
    <item>
      <title>Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454030#M284148</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; I am new to SAS and&amp;nbsp;trying to learn&amp;nbsp;where I am going wrong. I am trying to write a simple macro to determine the last day of the month. i have 2 questions with regards to this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Why is the following code failing ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. How can I call another macro within this macro definition ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%Let Input_Month = 2; 

*Define LastDayOfMonth Macro; 
%Macro LastDayOfMonth(Input_Month); 

	PROC SQL NoPrint;
		Select  CASE Input_Month
				WHEN Input_Month In (1,3,5,7,8,10,12)  THEN
			    31
				WHEN Input_Month In (4,6,9,11) THEN
				30
				WHEN Input_Month = 2 THEN
				28
				ELSE
				'unknown'
		End;

%put Result of LastDayOfMonth on Input_Month is &amp;amp;Test;

%MEND; 
* End of Macro LastDayOfMonth; 

%Let Test = %LastDayOfMonth(&amp;amp;Input_Month); &lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454030#M284148</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-04-13T19:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454031#M284149</link>
      <description>&lt;P&gt;Forget the macro , where is the essential FROM clause in a proc sql query or any sql for that matter?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454031#M284149</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-13T19:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454034#M284150</link>
      <description>&lt;P&gt;End of the month can easily be determined using the INTCK function. Why do you need more, why do you need a macro or SQL?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454034#M284150</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-13T19:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454035#M284151</link>
      <description>&lt;P&gt;Multiple issues.&lt;/P&gt;
&lt;P&gt;The assignment values you are using are a mix of numeric and character,&lt;/P&gt;
&lt;P&gt;you don't end the CASE statement correctly which would look more like:&lt;/P&gt;
&lt;PRE&gt;Select  CASE 
				WHEN Input_Month In (1,3,5,7,8,10,12)  THEN
			    31
				WHEN Input_Month In (4,6,9,11) THEN
				30
				WHEN Input_Month = 2 THEN
				28
				ELSE . as Somevar &lt;/PRE&gt;
&lt;P&gt;The "as variable" assigning the result to a variable,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no source supplied for Input_month (macro variable values are referenced as &amp;amp;input_month for example), which Proc SQL is going to expect a data table or view to select from&lt;/P&gt;
&lt;P&gt;The proc sql terminates with a "quit;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last day of month is YEAR dependent (leap years) so you may have another issue.&lt;/P&gt;
&lt;P&gt;But the whole logic involved is not needed if you use the proper date functions:&lt;/P&gt;
&lt;P&gt;If you need an all in macro code approach:&lt;/P&gt;
&lt;PRE&gt;%let input_month= 2;

%let lastday = %sysfunc(day(  %sysfunc(intnx(month,  %sysfunc(mdy(&amp;amp;input_month,1,1961)),0,E))));

%put &amp;amp;lastday;&lt;/PRE&gt;
&lt;P&gt;or data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let input_month= 2;

%let lastday = %sysfunc(day(  %sysfunc(intnx(month,  %sysfunc(mdy(&amp;amp;input_month,1,1961)),0,E))));

%put &amp;amp;lastday;&lt;/PRE&gt;
&lt;P&gt;I am using a year of 1961 because 1) you don't supply one and 2) that will force February to have 28 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454035#M284151</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-13T19:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454060#M284152</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;You may execute the following code in SQL Studio. This has no&amp;nbsp;FROM&amp;nbsp;clause in it and works perfectly fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Declare @Input_Mon Int = 2; 

Select LastDay = Case 
	    When @Input_Mon IN (1,3,5,7,8,10,12) Then
		31
		When @Input_Mon IN (4,6,9,11) Then 
		30 
		When @Input_Mon = 2 Then 
		28
		End &lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19791i5E8A4625EDA5BC6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 20:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454060#M284152</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-04-13T20:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454062#M284153</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am learning how to write macros in SAS and practice the same. While I understand this can be done with inbuilt functions, it was my attempt to try and learn and practice developing macros. Appreciate the insight.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 20:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454062#M284153</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-04-13T20:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454064#M284154</link>
      <description>&lt;P&gt;Oh sorry, i know nothing about it&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 21:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454064#M284154</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-13T21:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to write a simple macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454136#M284155</link>
      <description>&lt;P&gt;If you have a variable named TODAY which has the value of today's date, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INTNX('month',TODAY,0,'e')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;gives you the last day of today's month&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DAY(INTNX('month',TODAY,0,'e')) will give a number like 31 (if the month has 31 days, 30 if the month has 30 days, etc.)&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 11:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-write-a-simple-macro/m-p/454136#M284155</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-14T11:12:29Z</dc:date>
    </item>
  </channel>
</rss>

