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-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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