Calcite | Level 5

## Explain the following code;

%macro birth (BRTHDTC=,BRTHDT=);
if length(&BRTHDTC)=10 then &BRTHDTC._=&BRTHDTC;
else if length(&BRTHDTC)=7 then &BRTHDTC._=strip(&BRTHDTC)||'-15';
else if length(&BRTHDTC)=4 then &BRTHDTC._=strip(&BRTHDTC)||'-07-01';
else &BRTHDTC._='';
&BRTHDT=input(&BRTHDTC._,yymmdd10.);
format &BRTHDT date9.;
drop &BRTHDTC._;
%mend birth;

Q1: Can i the length with if statement without macro?

Q2: why did we use BRTHDTC_; what does it mean variable with underscore

2 REPLIES 2
Garnet | Level 18

## Re: Explain the following code;

The posted macro generates a code to be part of some program.

The arguments supplied are probably names of variables used in that program;

The variable &BRTHDTC holds probably a value of a date.

The date may be in   yy-mm-dd  format and a length of 10, or

it may be in a format of yyyy-mm and a length of 7, or jusy yyyy and length is 4.

The macro code creates a new (maybe temporary) date named &BRTHDTC._

(example, if &BRTHDTC = DTX then &BRTHDTC._ = DTX_ );

Remember that undersore  ('_') can be anywhere in a variable name.

Super User

## Re: Explain the following code;

@mahossain wrote:

%macro birth (BRTHDTC=,BRTHDT=);
if length(&BRTHDTC)=10 then &BRTHDTC._=&BRTHDTC;
else if length(&BRTHDTC)=7 then &BRTHDTC._=strip(&BRTHDTC)||'-15';
else if length(&BRTHDTC)=4 then &BRTHDTC._=strip(&BRTHDTC)||'-07-01';
else &BRTHDTC._='';
&BRTHDT=input(&BRTHDTC._,yymmdd10.);
format &BRTHDT date9.;
drop &BRTHDTC._;
%mend birth;

Q1: Can i the length with if statement without macro?

Q2: why did we use BRTHDTC_; what does it mean variable with underscore

Very definitely BRTHDTC_ was not used in the code. The dot in &BRTHDTC._ is used by the macro language to indicate concatenation of a macro variable resolved value, what ever &BRTHDTC might be and then append an _ character.

If the program had &BRTHDTC_ then with a probability approaching unity you would get an error with an undefined macro variable by that name.

Discussion stats
• 2 replies
• 340 views
• 0 likes
• 3 in conversation