BookmarkSubscribeRSS Feed
mahossain
Calcite | Level 5

%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
Shmuel
Garnet | Level 18

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.

 

ballardw
Super User

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 426 views
  • 0 likes
  • 3 in conversation