Hello,
I have a 'Calculation' Macro over 200 lines.
%macro calculated;
if c_ageyears=. and agemonths=. and ageyears ne . then do;
c_ageyears=floor(ageyears);
c_ageyears_fix=1;
end;
.
.
.
%mend calculated;
And I would like to use this calculating macro to the data step.
data update_test2016; set test2106; if c_ageyears=. and agemonths=. and ageyears ne . then do; c_ageyears=floor(ageyears); c_ageyears_fix=1; end; . . . run;
So when every time I run a new year, for example from 2017 to 2019, I have to copy 200 lines from the first macro into the data steps to do the calculation. Is there a way so that I could just use one or two command lines to run the macro repeatedly, such as %includes or something else? Thanks.
%include isn't needed.
This should work
data update_test2016;
set test2106;
%calculated
.
.
run;
					
				
			
			
				But how to direct the SAS run this macro file with specific file location?
It seems that the macro is written to make the calculation for any file that has all variables mentioned in it.
The part of the macro that you posted does not relate to a specific file.
To be able to use the macro in a data step you can either:
%include "\\pathway\Programs\macro_calculation.sas";
data update_test2016;
   set test2106;
...
   %calculated;
...
run;
OR
filename macros "\\pathway\Programs";
options sasautos=(macros, sasautos);
data update_test2016;
set test2106;
...
%calculated;
...
run;
					
				
			
			
				
			
			
			
			
			
			
			
		Given that this macro has variables specific to this task, I would just put it in your program above the data step.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.