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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 614 views
  • 0 likes
  • 3 in conversation