SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Transforming date format inside a macro statement?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Transforming date format inside a macro statement?

Using the macro below, &sysdate appears in the format DATEw. (10OCT12).

%let foldername= &sysdate.;

How do I make it appear in the format YYMON. (2012-OCT) instead, inside the macro statement (which is used in the precode of a DI Studio job)?

Thanks for your time. Smiley Happy


Accepted Solutions
Solution
‎10-10-2012 04:37 AM
Respected Advisor
Posts: 3,899

Re: Transforming date format inside a macro statement?

YYMON. returns in my environemt 2012OCT without a dash. But that's for a foldername may be even better.

%let foldername=%sysfunc(inputn(&sysdate,date9.),yymon.);

View solution in original post


All Replies
Solution
‎10-10-2012 04:37 AM
Respected Advisor
Posts: 3,899

Re: Transforming date format inside a macro statement?

YYMON. returns in my environemt 2012OCT without a dash. But that's for a foldername may be even better.

%let foldername=%sysfunc(inputn(&sysdate,date9.),yymon.);

Respected Advisor
Posts: 3,777

Re: Transforming date format inside a macro statement?

It might be better to use TODAY() function.

%let foldername=%sysfunc(today(),yymon.);
%put &foldername;
Respected Advisor
Posts: 3,899

Re: Transforming date format inside a macro statement?

Why? Are you having these week-long EG sessions in mind or do you have another reason for this statement?

Respected Advisor
Posts: 3,899

Re: Transforming date format inside a macro statement?

@Einar

Based on what I assume data_null had in mind the following for you to consider:

You are developing DI jobs which normally are run overnight in batch. What happens if your job runs over midnight at a month end. Which foldername should the job generate?

If you are using &sysdate then the date will be used when the job started, today() will give you the date when you call it in the job. Still: both might be wrong. There could be some downtime and your job starts after midnight - or even a day later because the server was really down and you need to run catch-up runs.

One way to avoid all these problems is to base all such date based name generation not on the calendar date but on the date of your data and you normally know from which date your data is.

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 265 views
  • 0 likes
  • 3 in conversation