BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10
     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
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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:

yearcutoff.png

 

  Hope this helps,

Cynthia

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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

Cynthia_sas
SAS Super FREQ

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:

yearcutoff.png

 

  Hope this helps,

Cynthia

 

CharlotteCain
Quartz | Level 8

I would recommend reading this book

 

https://www.sas.com/store/books/categories/usage-and-reference/carpenter-s-complete-guide-to-the-sas...

 

And then I bet your understanding would be spot on!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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