BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rick255
Calcite | Level 5

Hello,

 

I'm using SAS Enterprise version 7.15 HF8 (7.100.5.6214) (64-bit). I'm trying to change a date using data pulled from a Teradata server. The properties indicate the original field is Date9 and the output in SAS displays the dates as "ddmmmyyyy". I created a new table where I'm changing the date to "01JUN2019".

 

SAS identifies the new date as a character by default. When I try to change the field to Date9, the output is in numerical format and is displayed as "21701". I appreciate any help.

 

PROC SQL;
CREATE TABLE Have AS SELECT DISTINCT
'01JUN2019' AS START_DATE,
GROUP BY 1 ;QUIT;

 

data want;
set have
new = input(start_date, date9.);
drop start_date;
rename new=start_date;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

To make a date literal you need to add the letter D after the quoted string. To run a SELECT statement in PROC SQL you need to include a FROM clause. 

Note if you did successfully create a date value but just forgot to attach a date type format to it then the value is still a valid date value.  You just need to display it using the format.  The value 21,701 is the right value for the data '01JUN2019'd.  So just attach the format.

 

Note it is much easier to make simple datasets using SAS code instead of SQL code.

data have;
  START_DATE = '01JUN2019'd;
  format START_DATE date9.;
run;

 

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

@rick255 wrote:

Hello,

 

I'm using SAS Enterprise version 7.15 HF8 (7.100.5.6214) (64-bit). I'm trying to change a date using data pulled from a Teradata server. The properties indicate the original field is Date9 and the output in SAS displays the dates as "ddmmmyyyy". I created a new table where I'm changing the date to "01JUN2019".

 

SAS identifies the new date as a character by default. When I try to change the field to Date9, the output is in numerical format and is displayed as "21701". I appreciate any help.

 

PROC SQL;
CREATE TABLE Have AS SELECT DISTINCT
'01JUN2019' AS START_DATE,
GROUP BY 1 ;QUIT;

 

data want;
set have
new = input(start_date, date9.);
drop start_date;
rename new=start_date;
run;

 


'01JUN2019'

is a string, while

'01JUN2019'd

is a valid date literal. To display a SAS date value (like 21701) in human-readable form, use a proper date format, e.g. date9.

Tom
Super User Tom
Super User

To make a date literal you need to add the letter D after the quoted string. To run a SELECT statement in PROC SQL you need to include a FROM clause. 

Note if you did successfully create a date value but just forgot to attach a date type format to it then the value is still a valid date value.  You just need to display it using the format.  The value 21,701 is the right value for the data '01JUN2019'd.  So just attach the format.

 

Note it is much easier to make simple datasets using SAS code instead of SQL code.

data have;
  START_DATE = '01JUN2019'd;
  format START_DATE date9.;
run;

 

 

rick255
Calcite | Level 5
Thank you, I added "d" after '01JUN2019' in my original table and it worked

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 12899 views
  • 0 likes
  • 3 in conversation