Can I format Date Values in PROC SQL?

Yes, it is possible to format date values in PROC SQL. In PROC SQL, you can use the PUT and INPUT functions to convert dates and times into other formats. Additionally, the FORMAT statement can be used to format date values in SELECT statements. In PROC SQL, the INPUT and PUT functions convert values from one format to another, while the FORMAT statement formats the output of a SELECT statement in a specific way.


You can use the FORMAT statement within PROC SQL in SAS to format date values in a specific way.

The following example shows how to use the FORMAT statement in practice.

Example: Format Date Values in PROC SQL

Suppose we have the following dataset in SAS that contains information about the start date of promotions at some retail store and the total sales made:

/*create dataset*/
data my_data;
    format start_date date9.;
    input start_date :date9. sales;
    datalines;
01JAN2023 22
01FEB2023 16
14MAR2023 11
01MAY2023 32
13MAY2023 15
18AUG2023 11
20OCT2023 36
;
run;

/*view dataset*/
proc print data=my_data;

We can use PROC SQL with the FORMAT statement to select all rows from this dataset and display the values in the start_date column in a MM/DD/YY format:

/*select all rows and format start_date column using mmddyy8.*/ 
proc sql;
    select start_date format=mmddyy8., sales
    from my_data;
quit;

Notice that the values in the start_date column are now displayed in a MM/DD/YY format.

You can also use the FORMAT statement to format new variables created using PROC SQL.

For example, the following code shows how to create a new variable called end_date by adding 7 days to start_date and formatting it as date9. instead:

/*create new end_date column with specific format*/ 
proc sql;
    select start_date format=mmddyy8., start_date+7 as end_date format=date9., sales
    from my_data;
quit;

Notice that we were able to specify the format for both the start_date and end_date variables by using the FORMAT statement multiple times.

The following tutorials explain how to perform other common tasks in SAS:

x