<?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: arrary-convert sas dates to char dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882307#M348598</link>
    <description>&lt;P&gt;No such thing as "SAS char date".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned a thousand times already, dates should remain numeric, and you can format them to appear in many different ways, whatever you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, don't do this.&lt;/P&gt;</description>
    <pubDate>Sun, 25 Jun 2023 10:34:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-06-25T10:34:33Z</dc:date>
    <item>
      <title>arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882306#M348597</link>
      <description>&lt;P&gt;convert sas numeric date to sas char date:&lt;/P&gt;
&lt;P&gt;What is the reason that the required fields getting null value in this program?&lt;/P&gt;
&lt;P&gt;I want to get char dates in format YYYY-MM-DD&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x1 x2 x3 x4 x5;
cards;
20010101 20010101 20010101 20010101 20010101
20010801 20010701 20010301 20010122 20010115
;
Run;


data want;
set have;
/*array*/
Array t(5) X1 X2 X3 X4 X5;
Array q(5) _X1 _X2 _X3 _X4 _X5;
Array r(5) want_X1 want_X2 want_X3 want_X4 want_X5;
do i=1 to 5;
IF t(i) =0 then q(i)=.;
else q(i)=input(compress(put(t(i),best.)),yymmdd8.);/****SAS date***/
r(i)=put(q(i),YYMMDD10.);/**Convert sas date to char***/
end;
drop i;
Run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 10:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882306#M348597</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-06-25T10:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882307#M348598</link>
      <description>&lt;P&gt;No such thing as "SAS char date".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned a thousand times already, dates should remain numeric, and you can format them to appear in many different ways, whatever you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, don't do this.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 10:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882307#M348598</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-25T10:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882308#M348599</link>
      <description>&lt;P&gt;It means char value with structure&amp;nbsp; YYYY-MM-DD&lt;/P&gt;
&lt;P&gt;I need it as input for other system.&lt;/P&gt;
&lt;P&gt;This is the reason that I neec char values with structure&amp;nbsp; of date YYYY-MM-DD&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 10:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882308#M348599</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-06-25T10:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882315#M348600</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It means char value with structure&amp;nbsp; YYYY-MM-DD&lt;/P&gt;
&lt;P&gt;I need it as input for other system.&lt;/P&gt;
&lt;P&gt;This is the reason that I neec char values with structure&amp;nbsp; of date YYYY-MM-DD&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is the other system using the SAS data set directly or do you export the data from SAS to a text, or other layout, file that is read?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you ask:" What is the reason that the required fields getting null value in this program?" did you read your log?&lt;/P&gt;
&lt;P&gt;When I run your code this is the result:&lt;/P&gt;
&lt;PRE&gt;10   data want;
11   set have;
12   /*array*/
13   Array t(5) X1 X2 X3 X4 X5;
14   Array q(5) _X1 _X2 _X3 _X4 _X5;
15   Array r(5) want_X1 want_X2 want_X3 want_X4 want_X5;
16   do i=1 to 5;
17   IF t(i) =0 then q(i)=.;
18   else q(i)=input(compress(put(t(i),best.)),yymmdd8.);/****SAS date***/
19   r(i)=put(q(i),YYMMDD10.);/**Convert sas date to char***/
20   end;
21   drop i;
22   Run;

NOTE: Character values have been converted to numeric
      values at the places given by: (Line):(Column).
      19:1
NOTE: Invalid numeric data, '2001-01-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-01' , at line 19 column 6.
x1=20010101 x2=20010101 x3=20010101 x4=20010101 x5=20010101 _X1=14976
_X2=14976 _X3=14976 _X4=14976 _X5=14976 want_X1=. want_X2=. want_X3=.
want_X4=. want_X5=. i=6 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, '2001-08-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-07-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-03-01' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-22' , at line 19 column 6.
NOTE: Invalid numeric data, '2001-01-15' , at line 19 column 6.
x1=20010801 x2=20010701 x3=20010301 x4=20010122 x5=20010115 _X1=15188
_X2=15157 _X3=15035 _X4=14997 _X5=14990 want_X1=. want_X2=. want_X3=.
want_X4=. want_X5=. i=6 _ERROR_=1 _N_=2
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 2 observations and 15 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time
&lt;/PRE&gt;
&lt;P&gt;Problems: First you say you want a character value. Then you create an array of numeric values. If your "want" array is to hold character values then you define it as character.&lt;/P&gt;
&lt;P&gt;Second, you need to look at the results of this:&lt;/P&gt;
&lt;PRE&gt;put(t(i),best.)&lt;/PRE&gt;
&lt;P&gt;The Best format without width defaults to 12. So your result has 4 leading spaces. Which then FAILS miserably with the input function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your other program actually expect a . when your original "date" is 0? Sounds a bit flaky to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: if you are going to have code that tests for bad values, such as a "date" of 0, then provide at least one value in the data. If your use of "if t[i]=0 was to avoid the invalid data messages then there are better options. See below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input x1 x2 x3 x4 x5;
cards;
20010101 20010101 20010101 20010101 20010101
20010801 20010701 20010301 20010122 0
;
Run;


data want;
   set have;
   Array t(5) X1 X2 X3 X4 X5;
   Array r(5) $10 want_X1 want_X2 want_X3 want_X4 want_X5 ;
   do i=1 to 5;
       r[i]= put(input(put(t[i],8. -L),?? yymmdd8.),yymmddd10.);
   end;
   drop i;
Run;

 &lt;/PRE&gt;
&lt;P&gt;The ?? option on the input will suppress invalid data messages. NOTE use of the 8. format instead of best. Also the -L option on Put left justifies the result so you don't get leading spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last, never call a randomish string of digits like 20200122 a "date". It is a number perhaps but not a date except to people. If you add 1 to 20201231 you do not get 20210101 (jan 1 of the next year) you get a value of 20201232 which is just wrong for anything considered a "date".&lt;/P&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>Sun, 25 Jun 2023 13:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882315#M348600</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-25T13:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882316#M348601</link>
      <description>Why do you have such useless numbers in the first place?&lt;BR /&gt;Dates MUST ALWAYS be stored correctly, as counts of days, with a proper SAS format to be human-readable.&lt;BR /&gt;So go back to the process that brings the data into SAS, fix it, and then it‘s a simple PUT with YYMMDD10.</description>
      <pubDate>Sun, 25 Jun 2023 13:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882316#M348601</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-25T13:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882318#M348602</link>
      <description>&lt;P&gt;Just fix the ARRAY statement so that it defines a set of CHARACTER variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input x1-x5;
cards;
20010101 20010101 20010101 20010101 20010101
20010801 20010701 20010301 20010122 20010115
;
  
data want;
  set have;
  array t(5) X1-x5;
  array q(5) _X1-_X5;
  array r(5) $10 want_X1-want_X5;
  do i=1 to 5;
    if t(i) ne 0 then q(i)=input(put(t(i),z8.),yymmdd8.);
    r(i)=put(q(i),YYMMDD10.);
  end;
  drop i;
  format _x1-_x5 yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1687702997165.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85349iE8F298E8DD4A2C82/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1687702997165.png" alt="Tom_0-1687702997165.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 14:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882318#M348602</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-25T14:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882332#M348612</link>
      <description>Thanks a lot!&lt;BR /&gt;What is the meaning of ?? that you wrote</description>
      <pubDate>Sun, 25 Jun 2023 20:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882332#M348612</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-06-25T20:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882334#M348614</link>
      <description>&lt;P&gt;You are right but sometimes we get data sets with meaning of dates but with non sas dates values.&lt;/P&gt;
&lt;P&gt;I agree 100% that always need to write SAS dates in SAS dates fields but unfortunately we are living in a word when data is not always built well and then need to convert it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 20:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882334#M348614</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-06-25T20:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: arrary-convert sas dates to char dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882376#M348616</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks a lot!&lt;BR /&gt;What is the meaning of ?? that you wrote&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As my explanation says, it suppresses invalid data messages, just like the similar option on the Input statement.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jun 2023 23:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrary-convert-sas-dates-to-char-dates/m-p/882376#M348616</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-25T23:26:16Z</dc:date>
    </item>
  </channel>
</rss>

