DATA Step, Macro, Functions and more

Datestamp output

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Datestamp output

Hi,

 

I'm trying to save my SAS Table and first I want to rename it with the datestamp.

 

This is my code:

 

PROC FORMAT;
PICTURE datestamp(default=15)other='%Y%0m%0d%0H%0M%0S' (datatype=datetime);
RUN;

 

data FILENAME_%sysfunc(datetime(),datestamp);
set FILENAME;
RUN;

 

proc copy inlib=work outlib=output ;

  select FILENAME_%sysfunc(datetime(),datestamp);

run;

 

But it's not working because before the datestamp I have a blank...Something like "FILENAME_ 20170110163415"

And I don't understand why. Do you know?

 

Thanks


Accepted Solutions
Solution
‎01-10-2017 11:23 AM
Contributor
Posts: 33

Re: Datestamp output

I would set a macro variable for the datestamp and then call that.

 

PROC FORMAT;
PICTURE datestamp(default=15)other='%Y%0m%0d%0H%0M%0S' (datatype=datetime);
RUN;
 
%let datestamp=%sysfunc(datetime(), datestamp.);

data FILENAME_&datestamp.;
set FILENAME;
RUN;

View solution in original post


All Replies
Super User
Posts: 6,936

Re: Datestamp output

Use this

data _null_;
call symput('datestamp',strip(put(datetime(),datestamp.)));
run;

and use &datestamp in place of your %sysfunc's.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,256

Re: Datestamp output

Try %left.

Data never sleeps
Solution
‎01-10-2017 11:23 AM
Contributor
Posts: 33

Re: Datestamp output

I would set a macro variable for the datestamp and then call that.

 

PROC FORMAT;
PICTURE datestamp(default=15)other='%Y%0m%0d%0H%0M%0S' (datatype=datetime);
RUN;
 
%let datestamp=%sysfunc(datetime(), datestamp.);

data FILENAME_&datestamp.;
set FILENAME;
RUN;
Super User
Posts: 6,936

Re: Datestamp output

Also keep in mind that datetime() always returns the CURRENT date&time, so the results of your %sysfunc's would be different if the program ran in more than one second!

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,081

Re: Datestamp output

Could this be happening because your default length is 15 instead of 14?  You are only filling 14 characters.

Contributor
Posts: 45

Re: Datestamp output

Perfect,

 

Thank you for all your reply, it works

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 190 views
  • 6 likes
  • 5 in conversation