BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
deleted_user
Not applicable
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.
deleted_user
Not applicable
Thanks - I can't get the entire message to post....
deleted_user
Not applicable
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

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
  • 711 views
  • 0 likes
  • 1 in conversation