DATA Step, Macro, Functions and more

Date Functions in SAS

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

Date Functions in SAS


Dear TEam,

I have a little difficulty in understanding this topic from the paper mentioned below.

http://analytics.ncsu.edu/sesug/2006/SC11_06.PDF

Question1:

Is it true that when we use functions in Macro there is no trailing period after the name of the format??(theory on page 3 of the above paper says there is no need!!!!)

"The other thing of significance is that the informat and

format used in the InputN and PutN can be any valid SAS informat or format and there is no trailing

decimal."

I get the answer anyways with or without using the dot after the format name!!!!

%let Date = %Sysfunc( InputN( 01JAN2006 , Date9. ) ) ;


%put &Date;

Regards


Accepted Solutions
Solution
‎11-01-2012 02:50 PM
Valued Guide
Posts: 634

Re: Date Functions in SAS

Posted in reply to robertrao

The period or dot used with a format name is a parsing character.  It is needed so that the parser can detect a difference between a format name and a variable name.  In the macro language this is not necessary as there are no data set variables, only macro language elements (that start with a macro language trigger - & and %), and non macro language elements, which don't start with a trigger.  functions such as the INPUT function know that the second argument is a format, so in the macro language the period is not necessary.  I suspect that we should be grateful that the periods don't cause problems.

View solution in original post


All Replies
PROC Star
Posts: 7,471

Re: Date Functions in SAS

Posted in reply to robertrao

Karun: You can find a nice discussion about whether periods should or shouldn't be used at:

http://www.sascommunity.org/wiki/Macro_Programming_Best_Practices:_Styles,_Guidelines_and_Convention...

With the functions you mentioned you can also specify the length and number of decimal places in two additional fields to the right of the two you already used.  If you include those values they will override any values you may have used in specifying the informat to use.

Solution
‎11-01-2012 02:50 PM
Valued Guide
Posts: 634

Re: Date Functions in SAS

Posted in reply to robertrao

The period or dot used with a format name is a parsing character.  It is needed so that the parser can detect a difference between a format name and a variable name.  In the macro language this is not necessary as there are no data set variables, only macro language elements (that start with a macro language trigger - & and %), and non macro language elements, which don't start with a trigger.  functions such as the INPUT function know that the second argument is a format, so in the macro language the period is not necessary.  I suspect that we should be grateful that the periods don't cause problems.

Super Contributor
Posts: 1,041

Re: Date Functions in SAS

Thanks both of you for the response. Did u try it and see for yourself the above example i posted with a period and without after the Date

Regards

PROC Star
Posts: 7,471

Re: Date Functions in SAS

Posted in reply to robertrao

Karun,  Of course I tried it (but not until after you asked if I had)!

Surprised that you weren't surprised that neither the value, nor the informat, could have quotes around them.  The exact opposite is required in open code.  e.g.:

data have;

  input stuff $9.;

  date=inputn(stuff,"date9.");

  date2=InputN( "01JAN2006" , "Date9." );

  cards;

10jan2012

1nov2012

;

%let Date = %Sysfunc( InputN( 01JAN2006 , Date,9 ) ) ;

%put &date.;

Super Contributor
Posts: 1,041

Re: Date Functions in SAS

Hi,

I agree wid you altogether. I was reading about it too from the same paper I posted......

"Remember that the macro facility considers everything not

preceded by a % or & to be text, which is different from the data step where words have meaning and we

quote the words we want to be considered as text."

Regards

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 246 views
  • 6 likes
  • 3 in conversation