18 June 2014

Dealing with Time values in SAS

Time values should be read and saved into a dataset within the SAS environment. But before that programmer need to know, how SAS can capture the time values and save them in a SAS environment.

When a programmer works on any data, he has to depend on different types of data values during analysis, such as character values, numerical values, special character, date values, time values or amount values. But SAS has the capability to capture only standard numeric or character values, and any other formatted values are not captured by SAS because of its non standard special characters present in the values. Therefore while writing the SAS programs, programmers has to provide statements that can read and execute non-standard data, and these statements are referred to as Informat and Format statements. Of these two statements, Informat statement is used to read non-standard data and save that in the form of SAS understandable data value in a dataset, format statement is used to make that value user readable, which converts the SAS readable data value into user understandable data value.

Sometimes the non-standard data from an external file can contain time values; time values contain some special characters that are used to separate hours, minutes and seconds. Therefore to read different types of time values into a dataset, a programmer has to apply different types of informat statements. Let us see how to read time values into the SAS environment with different types of informat statements.

Time values might be in the format of 12 hours or 24 hours. There are different types of formats statements to read 12 hours and 24 hours time values separately. Here are some of the examples to read time values into SAS environment.

TIMEw. : This time-format will be able to read and convert both 24 hours time values and 12 hour time values, but this format depends on the character length that is specified when reading the time formatted values, as shown in the example with (w.). If the time character length is given with 8 dot, that is “TIME8.” then this format can read only 24 hours time formatted values. Whereas if the time format character length is given with 10 dot, that is “TIME10.” then this format can read only 12 hours time formatted values.

TIMEAMPMw. : This type of format will have the capability of reading time values into 12 hours format. This format also has the capability to convert the values which are in 24 hours into 12 hours time values.

TODw. : This is known as Time of the Day format, which is used to capture system time from computation process. This value is always displayed in the standard format of hours, minutes and seconds (hh:mm:ss).

HMSw. : This type of format is used to extract hours, minutes and seconds from 12 and 24 hrs time values, that is (hh:mm:ss).

HHMMw. : This has the capability to convert time values into only hours, minutes (hh:mm). Depending on the length of characters in the data. Time values are displayed in specific character length.

MMSSw. : This is used to extract only minute and seconds from time values, limiting the character values by assigning character length (w.).

HOURw. : This is used to extract only hours from 24 hours or 12 hours time values. Depending on the length specified only certain specific character limit can be assigned.

MINUTEw. : This is used to extract only minutes from the time formatted values with the character limit (w.), assigning length of the formatted value.

SECONDw. : This is used to extract only seconds from time values with character limit (w.), characters can be limited in this format.

DATETIMEw. : Sometimes the time values are included with date values also, to read such type of time values this format is used, which can read 12 hours and 24 hours formats. But those are read with different specified lengths (w.). For example 12 hours date and time values are read with 20 dot format, that is “Datetime20.”, whereas 24 hours date and time values are read with 18 dot format, that is “Datetime18.”.

DHMSw. : This type of format is used to extract day, hour, minute and seconds from the date and time formatted values with a specific character limit.

Conclusion: Thus, using these types of formats, time values can be formatted easily and saved to a SAS data set.

Clinnovo is a clinical innovation company. It is pioneer CRO industry in India. Clinnovo offers professional clinical research course , clinical data management course , SAS Courses and imaging training. Clinnovo has been serving different bio-pharma industries across the world with excellence and high quality. For more information contact at +91 9912868928, 040 64635501

1 comment:


  1. Thank you provide valuable informations and iam seacrching same informations,and saved my time SAS Online Training

    ReplyDelete