Sample 26012: How to change a character date value into a SAS date value in SAS® Enterprise Guide
You may have a SAS table with a character column with values such as 12/25/2005, 12/31/2005, etc. Your goal is to use the column in computations. The column, however, is defined as character and character columns can not be used in computations.
The following is a method that can be used in SAS Enterprise Guide to convert the column from character to a SAS date which can then be used in computations.
Use File
Open
From SAS Server/Binder to open the data with the character date column which you want to convert to a SAS date column. If the data is set to read only, click Data on the main toolbar and unselect Read-only to unprotect the data so that it may be edited. Click Yes when you are prompted about switching the data to update mode.
If you do not have write access to this data, right-click on the data icon and choose Export to save the data to a location on the SAS server where you have write access. Then open the data from the new location and unprotect it as instructed above.
Continue with the following step:
- Right-click on the column to be converted and select Properties.
- Change the type to Numeric and click Yes in the warning prompt regarding precision.
- Change the Group to Date.
- Click Informats; the selected value under Categories should be Date. Change the informat to ANYDTDTEw.
- Under Attributes, assign an overall width of 10.
- Click Formats; the selected value under Categories should be Date. Change the format to MMDDYYw.d.
- Under Attributes, assign an overall width of 10.
- Click OK. If the conversion results are correct in the Preview Results window, click Commit changes.
The result of this example is a SAS date column than can be used in calculations. The same technique can be used to convert between other column and data types.
SAS® Enterprise Guide can be used to convert columns from one type to another. This can be necessary, for example, when a character column is needed in computations. This sample steps you through converting a character date value to a SAS date value.
| Date Modified: | 2006-02-09 03:02:44 |
| Date Created: | 2006-01-24 11:57:52 |
Operating System and Release Information
| SAS System | SAS Enterprise Guide | Microsoft Windows XP Professional | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Datacenter Edition | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows 2000 Professional | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Enterprise Edition | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows Server 2003 Standard Edition | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows 2000 Server | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows 2000 Datacenter Server | 3.0 | | 9.1 TS1M3 | |
| Microsoft Windows 2000 Advanced Server | 3.0 | | 9.1 TS1M3 | |