<?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: Working with Dates in SAS - Informats and Formats in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202908#M50641</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't mention how you are importing the dataset but to assign specific informats you likely need a data step program to read them. Easiest is to use proc import to get a skeleton of code which appears in the log, at least with base SAS and assign the informat and formats.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS date variables are represented as the number of days since 1 Jan 1960 and to use all of the features that apply to dates you don want to create a SAS date valued variable not a simple numeric as you have been.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The informat that you want to read data in your example would be yymmdd. And to display dates in the same format use the yymmdd. format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the very nice things about having your data as SAS date values is you can use formats to create different analysis without adding or changing variables.&lt;/P&gt;&lt;P&gt;With a data set read with the yymmdd informat for your data take a look at differences in output from similar programs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var mmddyy10.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var weekday.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var year. .;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var yymon..;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you get similar behaviors with most analysis programs where groups are defined by the format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Aug 2015 19:55:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-08-19T19:55:06Z</dc:date>
    <item>
      <title>Working with Dates in SAS - Informats and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202906#M50639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am very confused with working with and manipulating dates from a data file in SAS. I have a text file that I use as a input file in a data step where dates are listed as 20150819, for example. When I input these, I usually input as a "date_var $8." informat, storing the variable as an 8-digit number, exactly as it appears on my text file input. Sometimes, I will input them as "date_var 8." informat, storing the variable as an 8-digit number. Neither of these informats seem to be helpful, because I get errors trying to use the YRDIF function. The only way I can get the YRDIF function to work is if I input the variables using the yymmdd8. informat. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I finish all my data manipulation, I want the output displayed as an 8-character date (ie 20150819). Ultimately, I don't want to informat the same variable three different ways just so that I can use the yymmdd8. informat for date calculations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please explain the differences between informats and formats for dates and why the manipulation and conversions are necessary?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Aug 2015 18:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202906#M50639</guid>
      <dc:creator>nbran</dc:creator>
      <dc:date>2015-08-19T18:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Dates in SAS - Informats and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202907#M50640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you are using the 8. format that means that SAS is storing the field as a number, not a date.&amp;nbsp; SAS stores numbers as hexadecimal so any number should be 8.&amp;nbsp; If you want to do calculations between dates you want the number to be stored as a date, not a number. SAS stores dates as the date difference from jan 1 1960, so without formatting the dates will be numbers but not what you are expecting.&amp;nbsp; There is a wealth of information out there if you google it.&amp;nbsp; Run this code and see if it helps at all, pay note to the formatting:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dates;&lt;/P&gt;&lt;P&gt;infile cards dsd;&lt;/P&gt;&lt;P&gt;informat num_date 8. char_date $8. mmddyy mmddyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format num_date 8. char_date $8. mmddyy mmddyy10.;&lt;/P&gt;&lt;P&gt;input num_date char_date mmddyy;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;20150819,20150819,08/19/2015&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data formats;&lt;/P&gt;&lt;P&gt;format date9 date9. date_date yymmdd8.;&lt;/P&gt;&lt;P&gt;set dates;&lt;/P&gt;&lt;P&gt;date9=mmddyy;&lt;/P&gt;&lt;P&gt;date_date = input(put(num_date,8.),yymmdd8.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Aug 2015 19:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202907#M50640</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-08-19T19:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Dates in SAS - Informats and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202908#M50641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't mention how you are importing the dataset but to assign specific informats you likely need a data step program to read them. Easiest is to use proc import to get a skeleton of code which appears in the log, at least with base SAS and assign the informat and formats.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS date variables are represented as the number of days since 1 Jan 1960 and to use all of the features that apply to dates you don want to create a SAS date valued variable not a simple numeric as you have been.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The informat that you want to read data in your example would be yymmdd. And to display dates in the same format use the yymmdd. format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the very nice things about having your data as SAS date values is you can use formats to create different analysis without adding or changing variables.&lt;/P&gt;&lt;P&gt;With a data set read with the yymmdd informat for your data take a look at differences in output from similar programs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var mmddyy10.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var weekday.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var year. .;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables Date_Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date_var yymon..;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you get similar behaviors with most analysis programs where groups are defined by the format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Aug 2015 19:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202908#M50641</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-08-19T19:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Dates in SAS - Informats and Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202909#M50642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;20150819 needs to be read with the yymmdd8. informat, SAS then stores the date in SAS date format (count of days, with day 1 = 01/01/1960). To make the date human-readable, assign a proper format for output (see the date and time category in the SAS formats documentation).&lt;/P&gt;&lt;P&gt;So, given your initial description, the input data step should look like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards;&lt;/P&gt;&lt;P&gt;input date yymmdd8.;&lt;/P&gt;&lt;P&gt;format date yymmddn8.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;20150819&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note the 'n' in the output format; it tells SAS to not use a separator between day/month/year.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2015 07:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-with-Dates-in-SAS-Informats-and-Formats/m-p/202909#M50642</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-08-20T07:04:34Z</dc:date>
    </item>
  </channel>
</rss>

