<?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 input into yyq. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855944#M338229</link>
    <description>Thank you so much for your input. Will take this to heard.&lt;BR /&gt;Worked flawlessly.</description>
    <pubDate>Fri, 27 Jan 2023 13:25:09 GMT</pubDate>
    <dc:creator>Freppa87</dc:creator>
    <dc:date>2023-01-27T13:25:09Z</dc:date>
    <item>
      <title>Macro input into yyq. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855917#M338218</link>
      <description>&lt;P&gt;I have a program which uses a input as&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let reportdate = Q3 2022;&lt;/P&gt;&lt;P&gt;And I having difficulties getting a readable datetime format from it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I have written is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let reportdate = Q3 2022;&lt;BR /&gt;%macro date_loop(report_date);
%let rep_date = %sysfunc(intnx('quarter', %sysfunc(input(&amp;amp;report_date, yyq6.)), 0));&lt;BR /&gt;/*&lt;SPAN&gt;%let date = %sysfunc(inputn(%qscan(&amp;amp;report_date,&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,%str( )),yyq.));*/&lt;/SPAN&gt;
  %do i = 1 %to 3;
    %let month_start = %sysfunc(intnx('month', &amp;amp;rep_date, i-1, 'beginning'));
    %let month_end = %sysfunc(intnx('month', &amp;amp;rep_date, i-1, 'end'));
    %put &amp;amp;=month_start;
    %put &amp;amp;=month_end;
  %end;
%mend;
%date_loop(&amp;amp;reportdate);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have been looking at using the %qscan function but have had no luck. Would appreciate some guidance and just some generell tips and tricks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With kind regards,&lt;/P&gt;&lt;P&gt;Fredrik&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 11:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855917#M338218</guid>
      <dc:creator>Freppa87</dc:creator>
      <dc:date>2023-01-27T11:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro input into yyq. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855936#M338224</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438888"&gt;@Freppa87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a program which uses a input as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let reportdate = Q3 2022;&lt;/P&gt;
&lt;P&gt;And I having difficulties getting a readable datetime format from it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I have written is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%let reportdate = Q3 2022;&lt;BR /&gt;%macro date_loop(report_date);
%let rep_date = %sysfunc(intnx('quarter', %sysfunc(input(&amp;amp;report_date, yyq6.)), 0));&lt;BR /&gt;/*&lt;SPAN&gt;%let date = %sysfunc(inputn(%qscan(&amp;amp;report_date,&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,%str( )),yyq.));*/&lt;/SPAN&gt;
  %do i = 1 %to 3;
    %let month_start = %sysfunc(intnx('month', &amp;amp;rep_date, i-1, 'beginning'));
    %let month_end = %sysfunc(intnx('month', &amp;amp;rep_date, i-1, 'end'));
    %put &amp;amp;=month_start;
    %put &amp;amp;=month_end;
  %end;
%mend;
%date_loop(&amp;amp;reportdate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have been looking at using the %qscan function but have had no luck. Would appreciate some guidance and just some generell tips and tricks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With kind regards,&lt;/P&gt;
&lt;P&gt;Fredrik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Lots of details that you need to pay attention to here when writing macros. First, before you run the macro, run this code to help with debugging:&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;options mprint symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, use date value that SAS will recognize, via an informat. Instead of&amp;nbsp;&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 reportdate = Q3 2022;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let reportdate=2022Q3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, you do not use quotes inside of %SYSFUNC (even though you would use quotes in the same command in a DATA step. Also, integer arithmetic should be performed inside the %EVAL() function.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Always (that's 100% of the time, no exceptions) work with days as the integer number of days since 01JAN1960 which then allows all SAS date functions (such as INTNX) and formats and informats to work properly, so 2022Q3 actually turns into 22827. Only when you need to make this value readable by humans (such as in titles or labels or file names) should you apply a format to make it appear as 01JUL2022 (or whatever format you choose).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the program ought to look like this:&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;options symbolgen mprint;
%let reportdate=2022Q3;
%macro date_loop(report_date);
%let rep_date = %sysfunc(inputn(&amp;amp;report_date, yyq7.));
  %do i = 1 %to 3;
    %let month_start = %sysfunc(intnx(month, &amp;amp;rep_date, %eval(&amp;amp;i-1), beginning));
    %let month_end = %sysfunc(intnx(month, &amp;amp;rep_date, %eval(&amp;amp;i-1), end));
    %put month_start %sysfunc(putn(&amp;amp;month_start,date9.));
    %put month_end %sysfunc(putn(&amp;amp;month_end,date9.));
  %end;
%mend;
%date_loop(&amp;amp;reportdate)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 13:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855936#M338224</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-27T13:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro input into yyq. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855944#M338229</link>
      <description>Thank you so much for your input. Will take this to heard.&lt;BR /&gt;Worked flawlessly.</description>
      <pubDate>Fri, 27 Jan 2023 13:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-input-into-yyq-format/m-p/855944#M338229</guid>
      <dc:creator>Freppa87</dc:creator>
      <dc:date>2023-01-27T13:25:09Z</dc:date>
    </item>
  </channel>
</rss>

