<?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: How to Bring Current Week Number of the Year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/246153#M46027</link>
    <description>&lt;P&gt;Thank you all fro your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jan 2016 17:32:07 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2016-01-26T17:32:07Z</dc:date>
    <item>
      <title>How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245417#M45796</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, I want to bring the last day of the month as format of YYYYMMDD (Example : 20151130) but it should also be previous month of the current date. After that, I need to bring the week number of the year. To Illustrate; I should see the macro as ‘201545’,’201546’,201547’,’201548’. Is there anyone who can help me write the macros which I mentioned (above).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my tries;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let P1_EOM_YYYYMMDD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = %substr(%sysfunc(intnx(month,&amp;amp;today,-1,end),yymmddn8.),1,8);&lt;/P&gt;
&lt;P&gt;%put &amp;amp;P1_EOM_YYYYMMDD ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/619.html" target="_blank"&gt;http://support.sas.com/kb/24/619.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My desired macro result should be -&amp;gt;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;LastMonth = 20151231&lt;/P&gt;
&lt;P&gt;%put &amp;amp;WeeksOfLastMonth =&amp;nbsp;&lt;SPAN&gt;‘201549’,’20150’,201551’,’201552’,2015532'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 11:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245417#M45796</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-01-22T11:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245420#M45797</link>
      <description>&lt;P&gt;Question 1, as always, why are you doing it in a macro. &amp;nbsp;Macro language is a Text Replacement, or Codce Generation toolkit. &amp;nbsp;It isn't a Base SAS replacement. &amp;nbsp;If you need to keep parameters, keep them in datasets so you can, via the use of Base SAS, manipulate them as data elements:&lt;/P&gt;
&lt;PRE&gt;data want;
  current_date=input("20151130",yymmdd8.);
  year=year(current_date);
  week=week(current_date);
  /* If needed then call that out here */
  call symput('P1_EOM',cats(year,week));
  format current_date date9.;
run;

%put &amp;amp;P1_EOM.;&lt;/PRE&gt;
&lt;P&gt;See how keeping it Base SAS simplifies the calls, keeps the code readable, uses functions. &amp;nbsp;If you keep *data* in a dataset, then you can do all the mapping you want, and if you really have to have that in a macro then call symput it only at the point you use that.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 11:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245420#M45797</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-22T11:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245421#M45798</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
week = .;
length outvar $100;
start = intnx('month',date(),-1,'begin');
end = intnx('month',date(),-1,'end');
do date = start to end;
  if week(date) ne week then do;
    outvar = catx(',',trim(outvar),"'"!!put(year(date),z4.)!!put(week(date),z2.)!!"'");
    week = week(date);
  end;
end;
call symput('WeeksOfLastMonth',trim(outvar));
call symput('LastMonth',put(end,yymmddn8.));
run;
%put &amp;amp;LastMonth;
%put &amp;amp;WeeksOfLastMonth;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See how I only used the data step language, as it is much better suited to doing calculations than the macro language, which is (as RW9 already mentioned) just a text generator. &lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 11:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245421#M45798</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-22T11:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245616#M45860</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is what I was trying to create. Thank you very much. When I execute your code in my environment, I don't get any error but the data set is created as empty. I think, I need to the change the mark as (") instead of('). I mean I need to see results as "201548","201549","201550","201551","201552" in the log. In the following statement I can't change the quotes because of the marks(" ' ") Do you have an idea ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; outvar &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;catx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;','&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;trim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;outvar&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;year&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;week&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;,Coming back to the your Macro question, I need to use the code more than one location in the SAS code.I thought If I create macro code I can call it whereever I want. I'd like to share that my program consists of a long code so that's why I need macro codes. But maybe I couldn't get your advises&amp;nbsp;literally, If so, sorry for that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll be waiting your thoughts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 11:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245616#M45860</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-01-23T11:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245648#M45867</link>
      <description>&lt;P&gt;You can always wrap a piece of SAS code into a macro so you avoid typing the same sequence repeatedly. But there's a difference between wrapping an easy-to-understand data step into a macro or creating a macro that is unnecessary complex, because it tries to do things in macro language that are easier done in data step language.&lt;/P&gt;
&lt;P&gt;Another method would be to save the data step into a little .sas file and %include that wherever you need the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the weeks enclosed in double quotes, then just replace the "'" (single quote enclosed by double quotes) in my code with '"' (double quote enclosed in single quotes)&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 18:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245648#M45867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-23T18:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245761#M45881</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;, I fixed the quote issue thank you for your help. I think I understood much better the macro discussion but I have to do more practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2016 23:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245761#M45881</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-01-24T23:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245811#M45902</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro xx;
%let LastMonth=%sysfunc(intnx(year,%sysfunc(today()),-1,end),yymmddn8.);

%let end=%sysfunc(intnx(year,%sysfunc(today()),-1,end));
%let StartWeek=%sysfunc(week(%sysfunc(intnx(month,&amp;amp;end,0,b))));
%let EndWeek=%sysfunc(week(&amp;amp;end));
%let year=%sysfunc(year(&amp;amp;end));

%let want_week=%sysfunc(quote(&amp;amp;year&amp;amp;StartWeek));
%do i=&amp;amp;StartWeek+1 %to &amp;amp;EndWeek;
 %let want_week=&amp;amp;want_week,%sysfunc(quote(&amp;amp;year&amp;amp;i));
%end;

%put &amp;amp;LastMonth &amp;amp;want_week ;
%mend xx;

%xx&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2016 06:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245811#M45902</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-25T06:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245812#M45903</link>
      <description>&lt;P&gt;Before choosing a tool, contemplate what you want to achieve.&lt;/P&gt;
&lt;P&gt;If you need to determine and set values for later use in a program, and you need data step functions for this, you are usually better off doing it in a data step and setting macro vars with call symput.&lt;/P&gt;
&lt;P&gt;The macro language is basically designed to help you in &lt;U&gt;creating code dynamically&lt;/U&gt;, not so much for doing calculations. The ability of the macro language to interface with data step functions is a helper for certain situations, but not its main purpose.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 06:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/245812#M45903</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-25T06:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bring Current Week Number of the Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/246153#M46027</link>
      <description>&lt;P&gt;Thank you all fro your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 17:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Bring-Current-Week-Number-of-the-Year/m-p/246153#M46027</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-01-26T17:32:07Z</dc:date>
    </item>
  </channel>
</rss>

