<?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 Creating SAS macro (YYYYMM) based on SAS macro (TIMESTAMP) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835775#M330440</link>
    <description>&lt;P&gt;I have a SAS macro that always indicates the end of the past month. It currently has this value: &lt;STRONG&gt;31AUG2022:23:59:59&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want a SAS macro that indicates this in a YYYYMM format. It should have this value: &lt;STRONG&gt;202208&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I've got this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let PrevPeriod_yyyy = %sysfunc(year(%sysfunc(datepart(&amp;amp;PrevPeriod_dttm))));
%let PrevPeriod_m = %sysfunc(month(%sysfunc(datepart(&amp;amp;PrevPeriod_dttm))));
%let PrevPeriod_mm = %sysfunc(put(%sysfunc(input(&amp;amp;PrevPeriod_m, best2.)), z2.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;Line 1 returns 2022.&lt;/LI&gt;
&lt;LI&gt;Line 2 returns 7&lt;/LI&gt;
&lt;LI&gt;Line 3 returns null&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The idea with line 3 was to force the single-digit month to have 2 digits. So that'd it return 07 instead of 7 (while maintaining monthly values like 10/11/12).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I can make line 3 work, then I can easily create 202207. Any idea what I'm doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 08:01:04 GMT</pubDate>
    <dc:creator>EinarRoed</dc:creator>
    <dc:date>2022-09-29T08:01:04Z</dc:date>
    <item>
      <title>Creating SAS macro (YYYYMM) based on SAS macro (TIMESTAMP)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835775#M330440</link>
      <description>&lt;P&gt;I have a SAS macro that always indicates the end of the past month. It currently has this value: &lt;STRONG&gt;31AUG2022:23:59:59&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want a SAS macro that indicates this in a YYYYMM format. It should have this value: &lt;STRONG&gt;202208&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I've got this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let PrevPeriod_yyyy = %sysfunc(year(%sysfunc(datepart(&amp;amp;PrevPeriod_dttm))));
%let PrevPeriod_m = %sysfunc(month(%sysfunc(datepart(&amp;amp;PrevPeriod_dttm))));
%let PrevPeriod_mm = %sysfunc(put(%sysfunc(input(&amp;amp;PrevPeriod_m, best2.)), z2.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;Line 1 returns 2022.&lt;/LI&gt;
&lt;LI&gt;Line 2 returns 7&lt;/LI&gt;
&lt;LI&gt;Line 3 returns null&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The idea with line 3 was to force the single-digit month to have 2 digits. So that'd it return 07 instead of 7 (while maintaining monthly values like 10/11/12).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I can make line 3 work, then I can easily create 202207. Any idea what I'm doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 08:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835775#M330440</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-09-29T08:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SAS macro (YYYYMM) based on SAS macro (TIMESTAMP)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835776#M330441</link>
      <description>&lt;P&gt;Since neither put nor input function can be used in %sysfunc, it may be easier to use the data step as follows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let PrevPeriod_dttm='31AUG2022:23:59:59'dt;
data _null_;
  call symputx('PrevPeriod_yyyymm',put(datepart(&amp;amp;PrevPeriod_dttm),yymmn6.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let PrevPeriod_mm = %sysfunc(putn(%sysfunc(inputn(&amp;amp;PrevPeriod_m., best2.)), z2.));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 08:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835776#M330441</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-09-29T08:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SAS macro (YYYYMM) based on SAS macro (TIMESTAMP)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835781#M330443</link>
      <description>&lt;P&gt;%SYSFUNC allows you to use a format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let wanted = %sysfunc(datepart(&amp;amp;PrevPeriod_dttm.),yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2022 08:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835781#M330443</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-29T08:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SAS macro (YYYYMM) based on SAS macro (TIMESTAMP)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835808#M330463</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If I can make line 3 work, then I can easily create 202207. Any idea what I'm doing wrong?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In addition to the correct answers already given, please understand that pulling apart text strings and then combining them is not the way to obtain calendar/date/month/year strings such as 202207. SAS has already done the hard work so you don't have to do this. Use the built in formats and informats to handle creation of calendar information strings. If you find yourself trying to pull apart calendar strings and somehow put them back together, then that is what you are doing wrong.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 11:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-macro-YYYYMM-based-on-SAS-macro-TIMESTAMP/m-p/835808#M330463</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-29T11:46:50Z</dc:date>
    </item>
  </channel>
</rss>

