- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
in my data set there is one column which repersents datetime .
I want its value should be in following format ..
YYYYMMDD HH24:MI:SS
if this format is not available then please tell me How can i create it ....
i have tried with proc format....
arvind
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS supports a number of ISO formats for datetimes that are common to transaction logs, web logs, XML, and JSON, and other interchanges.
Here's an example from the documentation (linked above):
data _null_;
input dtB :b8601dt15. dtE :e8601dt19.;
put dtB=b8601dt. dtE=e8601dt.;
datalines;
20120402T124022 2012-04-02T12:30:22
;
run;
Output:
dtB=20120402T124022 dtE=2012-04-02T12:30:22
Usually one of those formats will suit, as you're trying to conform to another standard.
However, you discovered that you can create your own custom datatime format like this:
proc format; picture BI_DTIME_FMT other = '%Y%0m%0d %0H:%0M:%0S' (datatype=datetime); run; data _null_; /*sampdtime=1551022320;*/ sampdtime='23FEB2009:15:32:00'dt; put sampdtime= BI_DTIME_FMT.; run;
To make that format "permanent", place it in a libname that is found in your OPTIONS FMTSEARCH path.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Scott Barry
SBBWorks, Inc.
SAS PROC FORMAT discussion:
http://support.sas.com/onlinedoc/913/getDoc/en/proc.hlp/a000063536.htm
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data dateformat;
format date datetime20. day yymmdd10. time time8.;
date = '30apr2007:13:23:45'dt;
day = datepart(date);
time = timepart(date);
day_char = put(day, yymmdd10.);
YYYYMMDD = put(substr(day_char, 1, 4)||substr(day_char, 6, 2)||substr(day_char, 9, 2), $8.);
HHMMSS = put(time, time8.);
YMDHMS = put(YYYYMMDD||' '||HHMMSS, $17.);
format YYYYMMDD $8. HHMMSS $8. YMDHMS $17.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
in my SAS data set there is a column like
colA numeric(8) .
it contain date.
i want its format like YYYYMMDD HH24:MI:SS;
the code which you sent ...i have used it ..using this we can create a variable "ymdhms" which contain date as YYYYMMDD HH24:MI:SS.
but i have to use it in proc format...
i have tried the following code to create my own format...
proc format library = mylib;
value ymdhms OTHER = [time.];
quit;
data _null_;
x=datetime();
format x ymdhms.;
put x=;
run;
after running this code the output was :
15:32:25
it was diplaying only time...because in [] brakets i have time. format.....
i need your help to explore your concept and implement it in my requirment.
once again thanks..waiting for reply....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
e.g.
data d1;
a = 123;
date = '30apr2007:13:23:45'dt;
format date datetime20.;
run;
data d2;
set d1;
if VFORMAT(date) = 'DATETIME20.' then do;
format date datetime20. day yymmdd10. time time8. ;
day = datepart(date);
time = timepart(date);
day_char = put(day, yymmdd10.);
YYYYMMDD = put(substr(day_char, 1, 4)||substr(day_char, 6, 2)||substr(day_char, 9, 2), $8.);
HHMMSS = put(time, time8.);
YMDHMS = put(YYYYMMDD||' '||HHMMSS, $17.);
format YYYYMMDD $8. HHMMSS $8. YMDHMS $17.;
output;
drop day time day_char YYYYMMDD HHMMSS;
end;
run;
proc print data = d2; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc format;
picture BI_DTIME_FMT
other = '%Y%0m%0d %0H:%0M:%0S' (datatype=datetime);
run;
data _null_;
/*sampdtime=1551022320;*/
sampdtime='23FEB2009:15:32:00'dt;
put sampdtime= BI_DTIME_FMT.;
run;
After creating this code ..What are the next step to make it permanently....
i have one SAS DATA SET , i want to change the format of its column like START_DATE .
so that it store the value according to created format....
i tried it in "work" library but its not working ..can u give me right solution...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The documentation has a long section on storing and accessing formats in permanent format libraries, including the use of the FMTSEARCH option to establish a search path in different SAS libraries for format catalogs.
http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a000146279.htm
In addition, the documenation has examples for PROC FORMAT that includes one whose title is, "Example 7: Retrieving a Permanent Format". And, of course, since you have to create the permanent format before you retrieve it, this example also shows how to create a permanent format.
cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Generally, as long as the variable values fall into the ranges defined by your format, and assuming the format library is available to your servers, then yes, you can assign that format to any variable in a SAS dataset.
However, in the context of the SAS Enterprise Intelligence Platform, which is the context in which SAS DI Studio exists, there is a special location under your application server context directory that is a pre-defined location for SAS formats. If you put your format catalog in that location, then you should not need a FMTSEARCH option in your code.
The Platform Administrator's guide and DI Studio documentation should outline the process for storing and accessing user-defined formats on the platform. There are some previous forum postings on this subject which may also be of use to you:
http://support.sas.com/forums/thread.jspa?messageID=11981⻍
http://support.sas.com/forums/thread.jspa?messageID=3658๊
http://support.sas.com/forums/thread.jspa?messageID=8216‘
cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Some good suggestions above. For cahnging the underlying value to a specific format, I normally use the nldate, nltime or nldatm functions. For the format I would use the suggestion as above.
proc format;
picture ymdH24MS
other = '%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
run;
data tmp;
x=datetime();
format x ymdH24MS.;
y=nldatm(x, '%Y-%m-%d %H:%M:%S');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS supports a number of ISO formats for datetimes that are common to transaction logs, web logs, XML, and JSON, and other interchanges.
Here's an example from the documentation (linked above):
data _null_;
input dtB :b8601dt15. dtE :e8601dt19.;
put dtB=b8601dt. dtE=e8601dt.;
datalines;
20120402T124022 2012-04-02T12:30:22
;
run;
Output:
dtB=20120402T124022 dtE=2012-04-02T12:30:22
Usually one of those formats will suit, as you're trying to conform to another standard.
However, you discovered that you can create your own custom datatime format like this:
proc format; picture BI_DTIME_FMT other = '%Y%0m%0d %0H:%0M:%0S' (datatype=datetime); run; data _null_; /*sampdtime=1551022320;*/ sampdtime='23FEB2009:15:32:00'dt; put sampdtime= BI_DTIME_FMT.; run;
To make that format "permanent", place it in a libname that is found in your OPTIONS FMTSEARCH path.