BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8


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

1 ACCEPTED SOLUTION

Accepted Solutions
ArtC
Rhodochrosite | Level 12

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

5 REPLIES 5
art297
Opal | Level 21

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.

ArtC
Rhodochrosite | Level 12

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.

robertrao
Quartz | Level 8

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

art297
Opal | Level 21

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.;

robertrao
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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