- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to create a file from SAS with date and timestamp on as below,
NAME_201907241615A.TXT
I could able to get the date in YYYYMMDD format using date() function with YYMMDDN8 format.
But i am finding difficult to get the time in 24 hr format. Or else if time is 9 AM , space is coming before 9 instead of 09.
So i tried this logic and it is working good as expected,
%let Time = %sysfunc(time(),time.) ;
%let Time_HH = %scan(&Time,1,:) ;
%let Time_MM = %scan(&Time,2,:) ;
HH=PUT(&TIME_HH,2.);
if length(hh)<3 and '0'>= hh < '10' then hh=repeat('0',2-length(hh))||strip(hh);
MM =PUT(&TIME_MM,2.);
if length(mm)<3 and '0'>= mm < '10' then mm=repeat('0',2-length(mm))||strip(mm);
var9="EDS"||"_"||"&VEN"||"_"||"&LOB"||"_"||"&TYP"||TRIM("_")||strip(%sysfunc(date(),YYMMDDN8.))||TRIM(HH)||TRIM(MM)||TRIM("A")||&VER;
The red highlighted portion i tried to get hour and minute as 2 digit (like 09), if the time is single digit.
I think there could be a straightforward approach , which i am missing. Is there is any other options to do this simply?Can we do this using picture clause in format?
Thanks,
Meenakshi
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let fileTimeStamp = %sysfunc(date(), yymmddn8.)%sysfunc(putc(%sysfunc(time(), b8601TM6.), $4.)) ;
%put &fileTimeStamp.;
@meenakshim wrote:
I am trying to create a file from SAS with date and timestamp on as below,
NAME_201907241615A.TXT
I could able to get the date in YYYYMMDD format using date() function with YYMMDDN8 format.
But i am finding difficult to get the time in 24 hr format. Or else if time is 9 AM , space is coming before 9 instead of 09.
So i tried this logic and it is working good as expected,
%let Time = %sysfunc(time(),time.) ;
%let Time_HH = %scan(&Time,1,:) ;
%let Time_MM = %scan(&Time,2,:) ;HH=PUT(&TIME_HH,2.);
if length(hh)<3 and '0'>= hh < '10' then hh=repeat('0',2-length(hh))||strip(hh);
MM =PUT(&TIME_MM,2.);
if length(mm)<3 and '0'>= mm < '10' then mm=repeat('0',2-length(mm))||strip(mm);var9="EDS"||"_"||"&VEN"||"_"||"&LOB"||"_"||"&TYP"||TRIM("_")||strip(%sysfunc(date(),YYMMDDN8.))||TRIM(HH)||TRIM(MM)||TRIM("A")||&VER;
The red highlighted portion i tried to get hour and minute as 2 digit (like 09), if the time is single digit.
I think there could be a straightforward approach , which i am missing. Is there is any other options to do this simply?Can we do this using picture clause in format?
Thanks,
Meenakshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to display numbers with leading zeros use the Z format.
880 data _null_; 881 x=5; 882 put x Z2.; 883 run; 05
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let fileTimeStamp = %sysfunc(date(), yymmddn8.)%sysfunc(putc(%sysfunc(time(), b8601TM6.), $4.)) ;
%put &fileTimeStamp.;
@meenakshim wrote:
I am trying to create a file from SAS with date and timestamp on as below,
NAME_201907241615A.TXT
I could able to get the date in YYYYMMDD format using date() function with YYMMDDN8 format.
But i am finding difficult to get the time in 24 hr format. Or else if time is 9 AM , space is coming before 9 instead of 09.
So i tried this logic and it is working good as expected,
%let Time = %sysfunc(time(),time.) ;
%let Time_HH = %scan(&Time,1,:) ;
%let Time_MM = %scan(&Time,2,:) ;HH=PUT(&TIME_HH,2.);
if length(hh)<3 and '0'>= hh < '10' then hh=repeat('0',2-length(hh))||strip(hh);
MM =PUT(&TIME_MM,2.);
if length(mm)<3 and '0'>= mm < '10' then mm=repeat('0',2-length(mm))||strip(mm);var9="EDS"||"_"||"&VEN"||"_"||"&LOB"||"_"||"&TYP"||TRIM("_")||strip(%sysfunc(date(),YYMMDDN8.))||TRIM(HH)||TRIM(MM)||TRIM("A")||&VER;
The red highlighted portion i tried to get hour and minute as 2 digit (like 09), if the time is single digit.
I think there could be a straightforward approach , which i am missing. Is there is any other options to do this simply?Can we do this using picture clause in format?
Thanks,
Meenakshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Nothing, it's just a style of defensive programming that means that its easier to port programs.
There are likely at least five different ways this could be solved, that's just one option that seems to align with what the user understand and wants.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank u so much for your comment. Its working good. Can you give me a sample to do the same using picture format if possible??
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's a close option:
proc format;
picture datetimeStamp
low-high='%Y%0m%0d%0H%0M%p' (datatype=datetime);
run;
%put %sysfunc(datetime(), datetimeStamp.);
You can play around with the date directives to customize it if needed.
Literals are documented here: