BookmarkSubscribeRSS Feed
Citrine10
Obsidian | Level 7

hi there

 

i pull data from a SQL environment into SAS. There is a date field in the table which changes to a 5 digit numeric value. How can I get the date to display as dd/mm/yyyy?

4 REPLIES 4
Kurt_Bremser
Super User

Apply the DDMMYY10. format.

SAS dates are counts of days, with 1960-01-01 being day zero. That translates to 5-digit integers for most of the dates you will work with.

Citrine10
Obsidian | Level 7

hi 

 

I see when I do a max on the date it gives the issue. 

PaigeMiller
Diamond | Level 26

@Citrine10 wrote:

 

I see when I do a max on the date it gives the issue. 


You have to apply a date format to any variables that might be a date, including the one extracted from the database via PROC SQL and any other date variables you create via a function.

--
Paige Miller
Kurt_Bremser
Super User

@Citrine10 wrote:

hi 

 

I see when I do a max on the date it gives the issue. 


The result of a MAX function is the raw value, SQL does not automatically apply the format of the source variable.

See this:

data have;
input dateval yymmdd10.;
format dateval yymmdd10.;
datalines;
2020-05-02
2020-07-13
;

proc sql;
select max(dateval) as dateval
from have
;
select max(dateval) as dateval format=yymmdd10.
from have
;
quit;

Result:

    dateval
   --------
      22109
              

     dateval
  ----------
  2020-07-13