<?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: confused about input/put, format/informat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291802#M270080</link>
    <description>&lt;P&gt;You are missing a crucial piece of the puzzle. SAS has two ways to represent dates: SAS dates and SAS datetimes. Both are just numbers but&amp;nbsp;SAS dates are expressed in days and SAS datetimes are expressed in seconds. Formats and informats are associated with one or the other, but never both. If you use a date format on a datetime value or a datetime format on a date value, you get either a meaningless display or an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To convert a SAS datetime that prints as&amp;nbsp;&lt;SPAN&gt;"09Dec2016 00:00:00" to a SAS date that can be displayed as "12-09-2016", use the function DATEPART(). To go from date to datetime, use function DHMS().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
dt = '09Dec2016 00:00:00'dt;
d = datepart(dt);
put dt= datetime16. d= mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Aug 2016 02:09:24 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-08-16T02:09:24Z</dc:date>
    <item>
      <title>confused about input/put, format/informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291799#M270079</link>
      <description>&lt;P&gt;I've been reading everywhere but I'm still I'm thoroughly confused about puts/inputs and formats/informats and just the concept&amp;nbsp;of converting back and forth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I right about this?&lt;/P&gt;
&lt;P&gt;Input is used when I enter raw data and give it a format. &amp;nbsp;i,e &amp;nbsp;I create a variable 1, and I declare it to be a numeric.&lt;/P&gt;
&lt;P&gt;Put &amp;nbsp;is used when I want to actually &lt;STRONG&gt;&lt;EM&gt;display&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;a format to look differently. &amp;nbsp;i,e Date to Date, i.e &amp;nbsp;convert "09Dec2016 00:00:00" to "12-9-2016."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;informat goes with input, format goes with put.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose, I have a value of "09Dec2016 00:00:00". &amp;nbsp;the current format is date. &amp;nbsp;when I used the put function with argument YYmmdd8, I got a date range out of bounds." &amp;nbsp;what did this happen?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, &amp;nbsp;my end goal is to convert the above date to a numeric format of YYYYMMDD, but I dont know where to start. &amp;nbsp;I can google the answer online and some of them use a combo of input and put together, but I do not understand the why or how.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 01:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291799#M270079</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2016-08-16T01:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: confused about input/put, format/informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291802#M270080</link>
      <description>&lt;P&gt;You are missing a crucial piece of the puzzle. SAS has two ways to represent dates: SAS dates and SAS datetimes. Both are just numbers but&amp;nbsp;SAS dates are expressed in days and SAS datetimes are expressed in seconds. Formats and informats are associated with one or the other, but never both. If you use a date format on a datetime value or a datetime format on a date value, you get either a meaningless display or an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To convert a SAS datetime that prints as&amp;nbsp;&lt;SPAN&gt;"09Dec2016 00:00:00" to a SAS date that can be displayed as "12-09-2016", use the function DATEPART(). To go from date to datetime, use function DHMS().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
dt = '09Dec2016 00:00:00'dt;
d = datepart(dt);
put dt= datetime16. d= mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Aug 2016 02:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291802#M270080</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-16T02:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: confused about input/put, format/informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291828#M270081</link>
      <description>&lt;P&gt;put() and input() are &lt;U&gt;conversion&lt;/U&gt; functions. The result of input() can be character or numeric, while the result of put() is always character.&lt;/P&gt;
&lt;P&gt;eg&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x1 = '41';
x2 = input(x1,$hex2.);&lt;BR /&gt;x3 = input(x1,hex2.);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will store a value of 'A' in character variable x2, and a value of 65 in numeric variable x3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input and put statements are use to read and write data in text form from/to external data sources; if no output file is specified, put will write to the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you correctly observed, the input statement and function uses informats, while put uses formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem happens because of an improper value which cannot be converted by the date format.&lt;/P&gt;
&lt;P&gt;Dates and datetimes are not variable types per se; both are just numeric, and have a date or datetime format attached.&lt;/P&gt;
&lt;P&gt;Since dates are numeric values counting the days from 01jan1960, while datetimes count seconds from 01jan1960:00:00:00, datetimes usually have values that make no sense as days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To extract the date part from a datetime value, use the datepart() function, and assign the newly created variable a date format.&lt;/P&gt;
&lt;P&gt;Or create a character variable to hold the formatted value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length newvar_numeric 5 newvar_char $8;
format newvar_numeric yymmddn8.;
newvar_numeric = datepart(oldvar);
put newvar_numeric=;
newvar_char = put(datepart(oldvar),yymmddn8.);
put newvar_char=;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Aug 2016 07:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291828#M270081</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-16T07:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: confused about input/put, format/informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291847#M270082</link>
      <description>&lt;P&gt;Trying to say it simple:&lt;/P&gt;
&lt;P&gt;- INPUT reads a string into a SAS variable. The INFORMAT instructs SAS how to read this string and convert it as a value of a SAS variable.&lt;/P&gt;
&lt;P&gt;- PUT WRITES a string to some output destination using a SAS variable. The FORMAT instructs SAS how to convert the SAS variable value and write the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and as others already wrote: SAS stores date as numbers but has two ways of doing so; either as number representing a date (days since 1/1/1960) or as number representing a datetime (seconds since 1/1/1960).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sooo... if you have a SAS numeric variable whose value stands for&amp;nbsp;todays&amp;nbsp;SAS datetime but you apply a format for dates then you'd end up in a date so far in the future that SAS doesn't even "bother" anymore to write this date.&lt;/P&gt;
&lt;P&gt;The other way round if you have a SAS numeric variable whose value stands for todays date and you apply a datetime format then you'd see some datetime value of 1960 (right now I'm getting&amp;nbsp;01JAN60:05:44:42).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And now that you understand how SAS date and datetime values work: You can convert them. There is a datepart() and timepart() function which allows you to extract the date or time part from a SAS datetime value. You could do this also on your own.&lt;/P&gt;
&lt;P&gt;Datetime is in seconds, date is in days - so simply divide the datetime value through the seconds of a day (86400) and take the integer of that. This is the corresponding SAS date value (and what the datepart() function does for you). Same goes with the timepart() function - it's the fractional&amp;nbsp;bit after the comma once you've devided through 86400.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that&amp;nbsp;didn't confuse more than it helped.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 11:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/confused-about-input-put-format-informat/m-p/291847#M270082</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-08-16T11:00:41Z</dc:date>
    </item>
  </channel>
</rss>

