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

I need to create a SAS timestamp starting not with today() but starting with May 01, 2019. Please help if you can.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

Where do you want that timestamp to go?

mauri0623
Quartz | Level 8

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.

Tom
Super User Tom
Super User

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 ;

 

Kurt_Bremser
Super User

@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?

ScottBass
Rhodochrosite | Level 12
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.  


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
mauri0623
Quartz | Level 8

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

Kurt_Bremser
Super User
%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;
Patrick
Opal | Level 21

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;
Tom
Super User Tom
Super User

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?

ScottBass
Rhodochrosite | Level 12

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.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1973 views
  • 0 likes
  • 6 in conversation