- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I all. I have a couple of questions about macros.
Does this
%let year3 = 2019;
%let year1 = %eval(&year3-2);
Do the same as this?
%let year1 = 2017;
%let year3 = %eval(&year1+2);
Another let statement in the program is this
%let folderyear = 20172019;
How to change the "20172019" to macro
I’d like to change this to macro, using year1year3 instead?
and the program also has these lines
libname pop "\\datafolder\PopulationData";
set pop.pop2009_2018_agelevel (where=(&year1 le year le &year3) );
How do i change "pop2009_2018_agelevel" to also use macros, so it will use year3 and year3-9, so in this case it would use a file named pop2010_2019_agelevel?
I think i'd need another let statement at the top of the program, like
%let year9 = %eval(&year3-9);
thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You don't seem to be calling any macros in that code. A call to a macro would look like:
%mymacro(parm1=1,parm2=abc)
You are just working with macro variables. They are two different things.
It looks like for your application you just want to extract parts of the macro variable value.
%SUBSTR() is a good function to use for that.
%let folderyear = 20172019;
%let year1=%substr(&folderyear,1,4);
%let year2=%substr(&folderyear,5);
Now that you have the two 4 digit strings in two macro variables you can use them to build your dataset name and WHERE= condition.
set pop.pop&year1._&year2._agelevel(where=(year between &year1. and &year2.));
Notice the periods after the macro variable names in building the dataset name. That is critical for this to work.
Without them you would be looking for macro variables named YEAR1_ and YEAR2_AGELEVEL instead of YEAR1 and YEAR2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You don't seem to be calling any macros in that code. A call to a macro would look like:
%mymacro(parm1=1,parm2=abc)
You are just working with macro variables. They are two different things.
It looks like for your application you just want to extract parts of the macro variable value.
%SUBSTR() is a good function to use for that.
%let folderyear = 20172019;
%let year1=%substr(&folderyear,1,4);
%let year2=%substr(&folderyear,5);
Now that you have the two 4 digit strings in two macro variables you can use them to build your dataset name and WHERE= condition.
set pop.pop&year1._&year2._agelevel(where=(year between &year1. and &year2.));
Notice the periods after the macro variable names in building the dataset name. That is critical for this to work.
Without them you would be looking for macro variables named YEAR1_ and YEAR2_AGELEVEL instead of YEAR1 and YEAR2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Gene