DATA Step, Macro, Functions and more

Easy date question

Posts: 51

Easy date question

Hi everybody,

I guess this is a very easy one, but I just cant figure it out on this friday afternoon...

I am passing a date9 value to another job in a loop, so it gets there as a macro variable.

So I have a variable &date, which resolves to 17998.

How do I convert it back to a DATE9. value? What's the name of the format of "17998".

data _null;
format x DATE9.;
x = input(resolve('&date'),DATE9.);

does not work.

Thanks a lot!

Super Contributor
Super Contributor
Posts: 3,176

Re: Easy date question

Use the SAS PUT function in an assignment statement with the desired format, such as DATE9. for your macro variable, either in a DATA step CALL SYMPUT or in a %LET statement using %SYSFUNC.

The SAS support website has a wealth of documentation and supplemental technical content - here is a Google advanced search argument which yielded several useful matches on this topic:

put macro variable date display

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: Easy date question

If &DATE resolves to 17998, there's no conversion needed, just the appropriate format.

Just X=&DATE will do the job.

Actualy DATE9. is a numeric format.

17998 and '11APR2009'd are the same.

To see X as DATE9, just apply the format DATE9. to the X, or use formatted print (put X date9.Smiley Wink

For example:

data _null_;
put X date9.;

and you will see the NUMERIC value 17998 formated with the NUMERIC format date9.

Hope it helps.

ps: btw the call resolve("&DATE") is useless "&DATE" just will do.

Greetings from Portugal.

Daniel Santos at
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation