I need to create a SAS timestamp starting not with today() but starting with May 01, 2019. Please help if you can.
Thank you!
datetime() returns the current system datetime as count of seconds since 1/1/1960
A string in the form of 'ddmonyyyy h24:mm:ss'dt also returns the count of seconds since 1/1/1960 for the string in the quotes.
Below sample code showcases the concept.
data _null_;
do dttm='01May2019 00:00:00'dt to '31May2019 00:00:00'dt by 86400;
put dttm B8601DT.;
end;
stop;
run;
Where do you want that timestamp to go?
So if I want it based on today I can use this code,
data _null_;
call symputx('timestamp', put(datetime(), B8601DT.));
run;
But I want it to start with may 01, 2019 instead.
So you want a datetime value for the date 01MAY2019? What time during that day? Why that day? Do you really need it in a macro variable? Why? How are you going to use the macro variable?
If you just want to make a macro variable that has a string in B8601DT. style format for some time on the first of may 2019 then why not just type to value directly?
%let TIMESTAMP=20190501T000000 ;
@mauri0623 wrote:
I need to create a SAS timestamp starting not with today() but starting with May 01, 2019. Please help if you can.
Thank you!
A single timestamp, or a series? If a series, what interval and over what range? If single, which time?
data test;
timestamp1=DHMS("01MAY2019"d,9,23,45);
timestamp2=DHMS("01MAY2019"d,hour(time()),minute(time()),second(time()));
format timestamp: datetime.;
run;
Get familiar with this page:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245860.htm
You don't have to memorize all of them - I certainly haven't - but know that this resource is here, and try to learn the functions you will likely use the most.
I guess I need to explain this a bit better, We receive files on a daily basis going forward. No problem with going forward with creating a timestamp. Problem is that the files we have for the month of May did not come in on a daily basis and we are in need of creating a timestamp for the May 01 through May 31. We need the timestamp as part of the naming convention for the SAS dataset that we are creating. So in fact I need a daily timestamp for the entire month of May by assuming that the data was received on a daily basis for the month of may. May 01, 2019 - May 31, 2019.
Thank you!
-mauri
%let start=20190501;
data _null_;
do i = input("&start.",yymmdd8.) to intnx('month',input("&start.",yymmdd8.),0,'e');
timestamp = dhms(i,0,0,0);
call execute('your code for import with' !! put(timestamp,b8601dt16.));
end;
run;
datetime() returns the current system datetime as count of seconds since 1/1/1960
A string in the form of 'ddmonyyyy h24:mm:ss'dt also returns the count of seconds since 1/1/1960 for the string in the quotes.
Below sample code showcases the concept.
data _null_;
do dttm='01May2019 00:00:00'dt to '31May2019 00:00:00'dt by 86400;
put dttm B8601DT.;
end;
stop;
run;
It sounds like you are saying the actual goal is to rename some SAS datasets that you already have.
How are they named now?
What names do you want them to have when the process is done.
For 31 files why don't you just do it by hand?
I answered your question as you originally posted. I'll leave it to others to answer your new question. Or perhaps you can modify what I posted to suit your actual requirements.
Good questions == good answers. The reverse is also true.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.