Not applicable
Posts: 0

# Macro question - this entire message is not posting...

If fyr=99 and yr=07 why does first year resolve to 2099 (vs 1999)?
%macro fy;%if 0<=&fyr<&yr %then %let first_year=%eval(2000 + &fyr);%else %if 20<=&fyr<=99 %then %let first_year=%eval(1900 + &fyr);
%if 0<=&yr<&yr %then %let last_year=%eval(2000 + &yr);
%else %if 20<=&yr<=99 %then %let last_year=%eval(1900 + &yr);
%put yr=&yr fyr=&fyr first_year=&first_year last_year=&last_year;
%mend fy;
%fy;

Not sure why the entire message isn't posting

Message was edited by: Teresa

Message was edited by: Teresa

Message was edited by: Teresa Message was edited by: Teresa
Not applicable
Posts: 0

## Re: Macro question - this entire message is not posting...

You should look at the setting of your YearCutOff option. Unless someone intervened, it is probably on the default install value, which I think is 1920. Using the cut off year, SAS imputes the century for two digit dates. Those prior to the year cut off are imputed to be 21st century, and those after start in the 20th century.

What this doesn't explain is why a financial (?) year value of 99 should match a year value of 7, unless the year value is simply a counter to derive a cohort for a financial model.

I think we need to see more of the code and some of the log to understand the issue better.
Not applicable
Posts: 0

## Re: Macro question

Thanks - I can't get the entire message to post....
Not applicable
Posts: 0

## Re: Macro question - this entire message is not posting...

Not all your code is posting because of the less than signs in the text.

From the Macro Expressions documentation ( I had to substitute LT for the symbol, and add spaces arount LT).

Note: Expressions in which comparison operators surround a macro expression, as in 10 LT &X LT 20, might or might not be the equivalent of a DATA step compound expression (depending on what the expression resolves to). To be safe, write the connecting operator explicitly, as in the expression 10 LT &X AND &X LT 20.

I would go a bit further and put the spaces around the symbolic tokens, and make one other change, use 00 instead of 0 to insure 9 is greater than 0 and not 9 is greater than a space or null or something:
[pre]
%if 00 LE &fyr AND &fyr LT &yr %then ...
[/pre]

Also, the code for last year should not work properly.

&yr is always equal to &yr, but your condition is less than, so it should always fail and never process the %then statement(s). Then, 07 is less than 20 so that should have failed as well. So where did last_year get its value of 2007 from? Message was edited by: Chuck
Discussion stats
• 3 replies
• 158 views
• 0 likes
• 1 in conversation