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

Hi Community

I'm in need of a function or a format that can help me convert a SAS date to a SAS date constant.

What I have is a variable containing a SAS date e.g. 21295, (21. of April 2018), what I need is to convert the SAS date to a SAS date constant i.e. '21apr2018'd.

How can I do this without choosing a date9. format for the SAS date and concatenating it with ''d?

Cheers,

Jakob

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

How can I do this without choosing a date9. format for the SAS date and concatenating it with ''d?

 

Why would  you rule that out?  It's exactly what you need.

 

If double quotes are permissible:

 

sdc = quote(put(date,date9.)) || 'd';

 

If single quotes are required:

 

sdc = cats("'", put(date, date9.), "'d");

 

View solution in original post

10 REPLIES 10
Kurt_Bremser
Super User

@Jakob_midspar wrote:

Hi Community

I'm in need of a function or a format that can help me convert a SAS date to a SAS date constant.

What I have is a variable containing a SAS date e.g. 21295, (21. of April 2018), what I need is to convert the SAS date to a SAS date constant i.e. '21apr2018'd.

How can I do this without choosing a date9. format for the SAS date and concatenating it with ''d?

Cheers,

Jakob

 


From my experience, you never need to convert. 21295 can be used in any place where you'd use '21apr2018'd.

 

And you always need to apply the date9 format, quotes, and the letter d to do this "conversion".

NewSASuser2018
Obsidian | Level 7

Hi Jacob,

 

I am by no means an expert! However, you might find this link helpful:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199367.htm

 

Best

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Could you clarify why?  Date literals are only really used to get date text which is not in data into SAS code.  There really isn't much purpose in it for any other circumstance?

Jakob_midspar
Obsidian | Level 7

Sure, I can try and clarify as to why I need that SAS date constant instead of simply the SAS date.

I'm getting data from a Teradata source using an ODBC connection and apparently the interpreter can only translate a SAS date constant to Teradata and not the SAS date itself, beats me why!

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not heard that before.  I think you probably mean dates in YYYY-MM-DD format, not SAS date literal, just a guess there.  

 

So when passing through SQL, you need to have the code in such a way that the database understands it, not SAS, as it is effectively all being passed over to the database.

emrancaan
Obsidian | Level 7

Try this

 

Data DateValue;
format dat date9. ;
	dat=21295;
	xdat=put(dat, date9.);
run;

once in character format. you can use it as variable or contant

 

Jakob_midspar
Obsidian | Level 7
That's how far I've gotten myself - but still needs the gnyffs and the d ( '21apr2018'd ) for it to be recognized as a SAS date constant.
Jakob_midspar
Obsidian | Level 7
The interpreter only understands '21apr2018'd as legit input not 21295.
Astounding
PROC Star

How can I do this without choosing a date9. format for the SAS date and concatenating it with ''d?

 

Why would  you rule that out?  It's exactly what you need.

 

If double quotes are permissible:

 

sdc = quote(put(date,date9.)) || 'd';

 

If single quotes are required:

 

sdc = cats("'", put(date, date9.), "'d");

 

Jakob_midspar
Obsidian | Level 7
Great solution, thanks for your input.
Cheers,
Jakob

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 2143 views
  • 2 likes
  • 6 in conversation