<?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: concatenate week(sasdate) in a string and retain leading zero for weeks 01 to 09 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531721#M5926</link>
    <description>&lt;P&gt;A custom format may be the easiest way, IMHO:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
picture mydtfmt (default=9)
low-high = 'Y%YFW%0V' (datatype=datetime)
;
run;

data work.example;
   dt="15JAN2019:12:24:00"dt;
   y = put (dt,mydtfmt.);
run;&lt;/PRE&gt;
&lt;P&gt;You can use either the %U %V or %W week definition&amp;nbsp;depending which you want. The 0 in %0V places a 0 when there is only a single digit to the week. By declaring the format for use with datetimes you need not extract the date part. The CASE of the % directives is case sensitive. Use of %y&amp;nbsp;would get a 2 digit year. The first Y and FW are literal strings inserted.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Jan 2019 17:18:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-01-31T17:18:22Z</dc:date>
    <item>
      <title>concatenate week(sasdate) in a string and retain leading zero for weeks 01 to 09</title>
      <link>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531709#M5924</link>
      <description>&lt;P&gt;i am having trouble with a simple format need.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My first attempt (which was with CATS and no PUT statement) resulted in single digit weeks for weeks 1 through 9.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below results in a single digit week number with a blank space where a zero should be.&amp;nbsp; The rest of data manipulations work but I would prefer to have the zero.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The remaining data manipulations provide a table showing a volume over a time line by week (across years, etc.).&amp;nbsp; a second path might be to skip creating this variable and present the data some other way but I have not see that alternate path.&amp;nbsp; &amp;nbsp; so help with keeping the zero is appreciated.&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;create table want AS
SELECT 
      some variables
      ,CAT('Yr', year(datepart(a_date)) , 'FW', put(week(datepart(a_date),'v'), 2.) ) AS FW_filter

from atable; 

&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;results are as such:&lt;/P&gt;&lt;P&gt;Yr2017FW 1&lt;/P&gt;&lt;P&gt;Yr2017FW 2&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would like&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yr2017FW01&lt;/P&gt;&lt;P&gt;Yr2017FW02&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 16:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531709#M5924</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2019-01-31T16:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate week(sasdate) in a string and retain leading zero for weeks 01 to 09</title>
      <link>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531714#M5925</link>
      <description>&lt;P&gt;Change 2. to Z2, which keeps the leading 0's.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CAT('Yr', year(datepart(a_date)) , 'FW', put(week(datepart(a_date),'v'), &lt;FONT size="5" color="#800080"&gt;&lt;STRONG&gt;Z&lt;/STRONG&gt;&lt;/FONT&gt;2.) ) &lt;/PRE&gt;
&lt;P&gt;Or use a custom format instead.&lt;/P&gt;
&lt;P&gt;Create format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture myCustomFmt (default=20)  low-high = 'Yr%YFW%0U' (datatype=datetime ) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;use format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(a_date, myCustomFmt.) as FW_filter&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255991"&gt;@yelkenli&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i am having trouble with a simple format need.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first attempt (which was with CATS and no PUT statement) resulted in single digit weeks for weeks 1 through 9.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below results in a single digit week number with a blank space where a zero should be.&amp;nbsp; The rest of data manipulations work but I would prefer to have the zero.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The remaining data manipulations provide a table showing a volume over a time line by week (across years, etc.).&amp;nbsp; a second path might be to skip creating this variable and present the data some other way but I have not see that alternate path.&amp;nbsp; &amp;nbsp; so help with keeping the zero is appreciated.&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;create table want AS
SELECT 
      some variables
      ,CAT('Yr', year(datepart(a_date)) , 'FW', put(week(datepart(a_date),'v'), 2.) ) AS FW_filter

from atable; 

&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;results are as such:&lt;/P&gt;
&lt;P&gt;Yr2017FW 1&lt;/P&gt;
&lt;P&gt;Yr2017FW 2&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yr2017FW01&lt;/P&gt;
&lt;P&gt;Yr2017FW02&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 17:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531714#M5925</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-31T17:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate week(sasdate) in a string and retain leading zero for weeks 01 to 09</title>
      <link>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531721#M5926</link>
      <description>&lt;P&gt;A custom format may be the easiest way, IMHO:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
picture mydtfmt (default=9)
low-high = 'Y%YFW%0V' (datatype=datetime)
;
run;

data work.example;
   dt="15JAN2019:12:24:00"dt;
   y = put (dt,mydtfmt.);
run;&lt;/PRE&gt;
&lt;P&gt;You can use either the %U %V or %W week definition&amp;nbsp;depending which you want. The 0 in %0V places a 0 when there is only a single digit to the week. By declaring the format for use with datetimes you need not extract the date part. The CASE of the % directives is case sensitive. Use of %y&amp;nbsp;would get a 2 digit year. The first Y and FW are literal strings inserted.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 17:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/concatenate-week-sasdate-in-a-string-and-retain-leading-zero-for/m-p/531721#M5926</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-31T17:18:22Z</dc:date>
    </item>
  </channel>
</rss>

