Thursday, May 10, 2012

A macro variable with "current date" in yymmdd10. format

You may already know that SAS system provides two automatic macro variables, &sysdate and &sysdate9, to contain the date that a SAS job or session began executing. Mot of the time, these two macro variables are good enough to be treated as current date. 

The issue I had is that these dates are in Date7. and Date9. format. I usually want to create folder/file names with dates in YYYY-MM-DD format, so that those folders/files could be sorted correctly. 

Here I present a simple way to create a macro variable &cdate with re-formatting &sysdate9 to YYYY-MM-DD format.

%let cdate=%sysfunc(putn("&sysdate9"d,yymmdd10.));
%put &cdate;

** Updated on 2012-06-05 **;
** If using today's date, instead of &sysdate or &sysdate9, Here is the codes **;
%let cdate=%sysfunc(date(),yymmdd10.);
%put &cdate;

1 comment:

  1. This site is mostly a walk-by for the entire data you wanted about this and didn’t know who to ask. Glimpse here, and also you’ll positively discover it. online casino gambling

    ReplyDelete