%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
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.
@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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.