DATA Step, Macro, Functions and more

the . at the end of date formats in macro variable is not necessary

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,636
Accepted Solution

the . at the end of date formats in macro variable is not necessary

Hi Macro Experts,

I just found out that the . is not necessary in format date9.

%let startdate = "30apr2012"d;

%let myfriday="%sysfunc(intnx(week.6,&startdate,0,b),date9)"d;

%put myfriday: &myfriday;

Is this true in all sas versions or just in newer version?

Thanks - Linlin


Accepted Solutions
Solution
‎04-14-2012 10:04 AM
PROC Star
Posts: 7,356

Re: the . at the end of date formats in macro variable is not necessary

Linlin,  I think the correct answer is probably when did SAS start working correctly when inserting a format with an ending period into a macro statement?

Take a look at: http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/cb3007714d347151

View solution in original post


All Replies
Solution
‎04-14-2012 10:04 AM
PROC Star
Posts: 7,356

Re: the . at the end of date formats in macro variable is not necessary

Linlin,  I think the correct answer is probably when did SAS start working correctly when inserting a format with an ending period into a macro statement?

Take a look at: http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/cb3007714d347151

Super Contributor
Posts: 1,636

Re: the . at the end of date formats in macro variable is not necessary

Thank you Art!  - Linlin

Valued Guide
Posts: 2,174

Re: the . at the end of date formats in macro variable is not necessary

thank you Art,

for referring to an old posting of mine (it must be about 10 years old! your memory is good!)

the issue hasn't changed - people (mostly those who call themselves sas programmers) see a trailing dot and imagine "format".

In fact that dot is only needed when a format is used on a put statement (likewise for informat on input statement) - to allow the compiler to recognise that you are not referring to another variable.

Deeply embedded in the data step compiler, the PUT() function expects a dot in a format name, also.

However PUTN (and informats in inputn) function has no need of the dot, as only a format name (in a variable value) can appear in the second parameter of the function. Having third and 4th parameters for "total formatted width" and "number of decimal places", it is the tolerance and generous flexibility of the SAS lanugage compilers that accept the dot, width and num-dec-pl. in the value of the format parameter.

So it is not a defect of the macro environment that %sysfunc( {function}, {format} ) allows you to place DATE9 in that {format} position, but generous flexibility.

(I believe PUTN() was introduced with SAS/AF-SCL and is not PUT(), because they couldn't extract the underlying compiler code that implements PUT() in a practical way because of the way that code is implemented)

peterC

Super Contributor
Posts: 1,636

Re: the . at the end of date formats in macro variable is not necessary

Hi Art and Peter,

I wish I had known you long time ago. Thank you very much for the detailed information. - Linlin

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 287 views
  • 3 likes
  • 3 in conversation