<?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: Format of macro variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529707#M5586</link>
    <description>&lt;P&gt;The "why" you are getting the results is easy.&amp;nbsp; Within a SAS program, this is the right way to refer to a specific date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'01jan2016'd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a date, it is just a text string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01jan2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question becomes what to do about it.&amp;nbsp; While there are a number of ways to correct the problem, one way would amount to a small change.&amp;nbsp; At the point where you have generated this as the value of your macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01jan2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a statement to modify the value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let ddebdet = "&amp;amp;ddebdet"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use doublequotes, not single quotes.&amp;nbsp; That changes your macro variable into an acceptable form to represent a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other ways to simplify the program, but this would be the easiest fix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Jan 2019 15:08:18 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-01-24T15:08:18Z</dc:date>
    <item>
      <title>Format of macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529695#M5585</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some issues with the format of my macro variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a program where I have to determine around 15 macro variables by hand and I am trying to automate the process.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;One of such variables would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ddebdet='01jan2016'd; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All of those 15 variables refer to different dates. I am trying to automate the process using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2018; 
%let month=11;    

data _null_;  
	call symputx('ddebdet', put(intnx('day',mdy(12,31,&amp;amp;year-3),0)+1,date9.)); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The idea is to adapt only two variables. Year and month, in this case and to generate&amp;nbsp;&lt;CODE class=" language-sas"&gt;01jan2016 automatically.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;This is the output that I'm getting:&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2275  %put &amp;amp;ddebdet;
01JAN2016
2276
2277  %let ddebdet='01jan2016'd;
2278  %put &amp;amp;ddebdet;
'01jan2016'd
2279
2280
2281  %let year=2018;
2282  %let month=11;
2283
2284  data _null_;
2285      call symputx('ddebdet', put(intnx('day',mdy(12,31,&amp;amp;year-3),0)+1,date9.));
2286  run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2287
2288
2289  %put &amp;amp;ddebdet;
01JAN2016&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see there is a difference between&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2278  %put &amp;amp;ddebdet;
'01jan2016'd&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2289  %put &amp;amp;ddebdet;
01JAN2016&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It is quite problematic because the rest of my code doesn't work with the auto generated solution. For example this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data det;
   set data
    (where=(&amp;amp;ddebdet&amp;lt;=datepart(dtismaj)&amp;lt;=&amp;amp;dfindet and ctyp='350')); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Returns the following error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "DDEBDET".
1230  01JAN2016
        -------
        22
        76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;,
              =, &amp;gt;, &amp;gt;=, AND, EQ, GE, GT, LE, LT, NE, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't really understand why I am having this issue.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 14:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529695#M5585</guid>
      <dc:creator>pkopersk</dc:creator>
      <dc:date>2019-01-24T14:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format of macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529707#M5586</link>
      <description>&lt;P&gt;The "why" you are getting the results is easy.&amp;nbsp; Within a SAS program, this is the right way to refer to a specific date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'01jan2016'd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a date, it is just a text string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01jan2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question becomes what to do about it.&amp;nbsp; While there are a number of ways to correct the problem, one way would amount to a small change.&amp;nbsp; At the point where you have generated this as the value of your macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01jan2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a statement to modify the value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let ddebdet = "&amp;amp;ddebdet"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use doublequotes, not single quotes.&amp;nbsp; That changes your macro variable into an acceptable form to represent a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other ways to simplify the program, but this would be the easiest fix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529707#M5586</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-24T15:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Format of macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529709#M5587</link>
      <description>&lt;P&gt;Adding to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;said, generally you would not want to format the macro variables at all. Just use straight unformatted SAS date values or unformatted SAS date/time values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only times you would want formatting is for human readability when outputting results, or human readability when inputting results. But its less work to code these things without the formatting for use in the macro processor, where human readability is not required.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529709#M5587</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-24T15:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Format of macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529722#M5590</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have to filter dates in SAS then you need to pass a date value, i.e. the value you have passed need to be understood by SAS. Leave the date value as numeric without formatting it, if you want to use a formatted value then convert that numeric value into your formatted vaue.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2018;
%let month=11;

%let date=%sysfunc(mdy(&amp;amp;month,01,&amp;amp;year));

%put &amp;amp;=date;

%let date_formated=%sysfunc(mdy(&amp;amp;month,01,&amp;amp;year),mmddyy10.);
%put &amp;amp;=date_formated;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jan 2019 15:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-of-macro-variable/m-p/529722#M5590</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-01-24T15:52:01Z</dc:date>
    </item>
  </channel>
</rss>

