<?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: Data conversion from Date to a Character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914888#M360531</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am having a problem tring to modify a column of data. I am trying to convert the values of the month field to a Character (FEB2023, MAR2023, APR2023)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MONTH&lt;/STRONG&gt;&lt;BR /&gt;202302&lt;BR /&gt;202303&lt;BR /&gt;202304&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is the TYPE of the current MONTH variable?&amp;nbsp; &amp;nbsp;Run PROC CONTENTS on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What TYPE to you want for the NEW variable?&amp;nbsp; To you want to make a character variable with strings like 'FEB2003'?&amp;nbsp; Or you do want a numeric variable with values like '01FEB2003'd that are formatted to print as FEB2003?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is already character then what is its storage length?&amp;nbsp; If it is only $6 then you cannot put 7 characters into it, so you will need to either make a new variable or set the length before referencing the old dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric what (if any) FORMAT specification is attached to it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is numeric with the YYMMN6. format attached then change the format to MONYY7. instead.&amp;nbsp; You could do that without creating a new dataset by using PROC DATASETS to change the format that is attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is numeric without any special format attached then you don't have dates, just number like 202,302 that only look to humans like they might be dates in yyy,ymm format.&amp;nbsp; So first convert the number into an actual string and then convert it to a date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = input(put(month,z6.),yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then either attach the MONYY7. format to the new numeric variable. Or use the PUT() function to generate a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is character you can so the same thing, only skip the initial PUT() since you already have a digit string that the INPUT() function can use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2024 16:57:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-07T16:57:02Z</dc:date>
    <item>
      <title>Data conversion from Date to a Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914886#M360530</link>
      <description>&lt;P&gt;I am having a problem tring to modify a column of data. I am trying to convert the values of the month field to a Character (FEB2023, MAR2023, APR2023)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MONTH&lt;/STRONG&gt;&lt;BR /&gt;202302&lt;BR /&gt;202303&lt;BR /&gt;202304&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 16:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914886#M360530</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2024-02-07T16:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Data conversion from Date to a Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914888#M360531</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am having a problem tring to modify a column of data. I am trying to convert the values of the month field to a Character (FEB2023, MAR2023, APR2023)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MONTH&lt;/STRONG&gt;&lt;BR /&gt;202302&lt;BR /&gt;202303&lt;BR /&gt;202304&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is the TYPE of the current MONTH variable?&amp;nbsp; &amp;nbsp;Run PROC CONTENTS on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What TYPE to you want for the NEW variable?&amp;nbsp; To you want to make a character variable with strings like 'FEB2003'?&amp;nbsp; Or you do want a numeric variable with values like '01FEB2003'd that are formatted to print as FEB2003?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is already character then what is its storage length?&amp;nbsp; If it is only $6 then you cannot put 7 characters into it, so you will need to either make a new variable or set the length before referencing the old dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric what (if any) FORMAT specification is attached to it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is numeric with the YYMMN6. format attached then change the format to MONYY7. instead.&amp;nbsp; You could do that without creating a new dataset by using PROC DATASETS to change the format that is attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is numeric without any special format attached then you don't have dates, just number like 202,302 that only look to humans like they might be dates in yyy,ymm format.&amp;nbsp; So first convert the number into an actual string and then convert it to a date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = input(put(month,z6.),yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then either attach the MONYY7. format to the new numeric variable. Or use the PUT() function to generate a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If MONTH is character you can so the same thing, only skip the initial PUT() since you already have a digit string that the INPUT() function can use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 16:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914888#M360531</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-07T16:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Data conversion from Date to a Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914889#M360532</link>
      <description>it is a date value in that field. I think i finally worked wround a solution.&lt;BR /&gt;&lt;BR /&gt;input(MONTH, yymmn6.) as MONTH format-monyy7. &lt;BR /&gt;&lt;BR /&gt;This gave me the desired output.&lt;BR /&gt;Thank you Tom for your input!</description>
      <pubDate>Wed, 07 Feb 2024 16:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914889#M360532</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2024-02-07T16:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Data conversion from Date to a Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914890#M360533</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;it is a date value in that field. I think i finally worked wround a solution.&lt;BR /&gt;&lt;BR /&gt;input(MONTH, yymmn6.) as MONTH format-monyy7. &lt;BR /&gt;&lt;BR /&gt;This gave me the desired output.&lt;BR /&gt;Thank you Tom for your input!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If that worked then you did NOT have a date value.&amp;nbsp; In fact you did not even have a numeric variable.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 17:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-conversion-from-Date-to-a-Character/m-p/914890#M360533</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-07T17:01:37Z</dc:date>
    </item>
  </channel>
</rss>

