BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

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.

5 REPLIES 5
PaigeMiller
Diamond | Level 26

%include isn't needed.

 

This should work

 

data update_test2016;
set test2106;
%calculated
.
.
run;
--
Paige Miller
ybz12003
Rhodochrosite | Level 12

But how to direct the SAS run this macro file with specific file location?

\\pathway\Programs\macro_calculation.sas

Shmuel
Garnet | Level 18

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;
PaigeMiller
Diamond | Level 26

Given that this macro has variables specific to this task, I would just put it in your program above the data step.

--
Paige Miller
Reeza
Super User
You generally put things in a macro if they'll be re-used or need to be generalized somehow. I fail to see how this is generalized, so I'm assuming this is being done because you plan to repeat it a few times in different places?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1106 views
  • 0 likes
  • 4 in conversation