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
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 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".
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
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?
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!
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.
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
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");
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!
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.