options yearcutoff=1950; %macro y2kopt(date2); %if &date2 >= 14610 %then %do; options yearcutoff=2000; %end; %else %do; options yearcutoff=1900; %end; %mend; %let date=14610; options yearcutoff=1920; %y2kopt(&date)
The SAS date for January 1, 2000, is 14610. What is the value of YEARCUTOFF when the macro Y2kopt finishes execution?
a. | 1900 |
b. | 1920 |
c. | 1950 |
d. | 2000 |
Hi:
The macro program is very straightforward and if you have studied the Macro Language, then it should be very easy to read the macro program.
In pseudo-code:
If the value of macro variable &date2 is GE 14610 then issue an options statement for YEARCUTOFF=2000
else If the value of macro variable &date2 is LT 14610 then issue an options statement for YEARCUTOFF=1900
The %MACRO/%MEND is causing the macro program Y2KOPT to be compiled and stored until it is ready to be used. The macro is defined as having 1 positional parameter named DATE2 and referred to in the macro program as &DATE2.
The program starts with an OPTIONS statement that initially sets YEARCUTOFF to 1950, but that is really a distractor, as is the other OPTIONS statement that sets YEARCUTOFF to 1920.
The %LET statement that is outside the macro definition program creates a Global Macro variable called &DATE with a value of 14610 (and the question tells you that this value 14610, when it represents a date is the SAS date for January 1, 2000, which is nice to know, but the macro program uses the numeric value).
The macro program is invoked with the statement:
%y2kopt(&date)
and that means it is essentially the same as having:
%y2kopt(14610)
Which means that the parameter &DATE2 will hold the value 14610. So, the %IF test will be true and the first OPTIONS statement in the macro program will be sent for execution.
You can prove this to yourself by using some debugging techniques like MPRINT/SYMBOLGEN and using %PUT along with testing the value of YEARCUTOFF at every step along the way, as shown below:
Hope this helps,
Cynthia
@mona4u wrote:
options yearcutoff=1950; %macro y2kopt(date2); %if &date2 >= 14610 %then %do; options yearcutoff=2000; %end; %else %do; options yearcutoff=1900; %end; %mend; %let date=14610; options yearcutoff=1920; %y2kopt(&date)The SAS date for January 1, 2000, is 14610. What is the value of YEARCUTOFF when the macro Y2kopt finishes execution?
a. 1900 b. 1920 c. 1950 d. 2000
Try it.
Hi:
The macro program is very straightforward and if you have studied the Macro Language, then it should be very easy to read the macro program.
In pseudo-code:
If the value of macro variable &date2 is GE 14610 then issue an options statement for YEARCUTOFF=2000
else If the value of macro variable &date2 is LT 14610 then issue an options statement for YEARCUTOFF=1900
The %MACRO/%MEND is causing the macro program Y2KOPT to be compiled and stored until it is ready to be used. The macro is defined as having 1 positional parameter named DATE2 and referred to in the macro program as &DATE2.
The program starts with an OPTIONS statement that initially sets YEARCUTOFF to 1950, but that is really a distractor, as is the other OPTIONS statement that sets YEARCUTOFF to 1920.
The %LET statement that is outside the macro definition program creates a Global Macro variable called &DATE with a value of 14610 (and the question tells you that this value 14610, when it represents a date is the SAS date for January 1, 2000, which is nice to know, but the macro program uses the numeric value).
The macro program is invoked with the statement:
%y2kopt(&date)
and that means it is essentially the same as having:
%y2kopt(14610)
Which means that the parameter &DATE2 will hold the value 14610. So, the %IF test will be true and the first OPTIONS statement in the macro program will be sent for execution.
You can prove this to yourself by using some debugging techniques like MPRINT/SYMBOLGEN and using %PUT along with testing the value of YEARCUTOFF at every step along the way, as shown below:
Hope this helps,
Cynthia
I would recommend reading this book
And then I bet your understanding would be spot on!
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!
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.