Case2: Extract the parts of the date; When dealing with characters, the Scan function used times will readily break out the components. For example Year = Scan ( Cvar , 3); Working a numeric version is a little more complex. 1000000 Month = Int( Nvar / ); 1000000 10000 Day = Int ( ( Nvar - Month * ) / ); 1000000 10000 Year = Nvar - Month * - Day * ; This gives the desired results. Trust me. Case3: Change appearance of date such as changing the order of the year, month, and day. As long as we are simply rearranging our parts, this is relatively simple if we have broken out the Year, Month, and Day. For Cvar, we simply concatenate the components 1 Month = Scan ( Cvar , ); 2 Day = Scan ( Cvar , ); 3 Year = Scan ( Cvar , ); Retain separator '/' ; NewCvar = Catx ( separator , Year , Month , Day ) ; drop Separator; For the Nvar, we simply add the parts: NewNvar = Year * 1000000 + Month * 10000 + Day; Case4: Calculate intervals or new dates related to our current one. This is where things get really, really complicated. We would have to create numeric variables if we had our date in a character string and then in either case, we would have to count the intervening number of years, months, and days in order to figure out the result. Don’t try this at home, or, more especially, at work. SAS to the Rescue I haven’t looked back to see when the feature was introduced but SAS offers methods to store a date as the number of days before or after a fixed date, Jan 1, 1960. I’m not sure whether this feature was available in other languages back then but modern data bases and some languages use similar based methods of storing dates. In order to store a date in this way in SAS, we Make a direct assignment using a date literal value Date = ‘21Nov2016’d;
Case2: Extract the parts of the date; When dealing with characters, the Scan function used times will readily break out the components. For example Year = Scan ( Cvar , 3); Working a numeric version is a little more complex. Month = Int( Nvar / 1000000 ); Day = Int ( ( Nvar - Month * 1000000 ) / 10000 ); Year = Nvar - Month * 1000000 - Day * 10000 ; This gives the desired results. Trust me. Case3: Change appearance of date such as changing the order of the year, month, and day. As long as we are simply rearranging our parts, this is relatively simple if we have broken out the Year, Month, and Day. For Cvar, we simply concatenate the components Month = Scan ( Cvar , 1 ); Day = Scan ( Cvar , 2 ); Year = Scan ( Cvar , 3 ); Retain separator '/' ; NewCvar = Catx ( separator , Year , Month , Day ) ; drop Separator; For the Nvar, we simply add the parts: NewNvar = Year * 1000000 + Month * 10000 + Day; Case4: Calculate intervals or new dates related to our current one. This is where things get really, really complicated. We would have to create numeric variables if we had our date in a character string and then in either case, we would have to count the intervening number of years, months, and days in order to figure out the result. Don’t try this at home, or, more especially, at work. SAS to the Rescue I haven’t looked back to see when the feature was introduced but SAS offers methods to store a date as the number of days before or after a fixed date, Jan 1, 1960. I’m not sure whether this feature was available in other languages back then but modern data bases and some languages use similar methods of storing dates. In order to store a date in this way in SAS, we Make a direct assignment using a date literal value Date = ‘21Nov2016’d; based
sas-doesnt-store-dates.docx