BookmarkSubscribeRSS Feed
ChuksManuel
Pyrite | Level 9

Hello programmers,

I'm doing a macro project and I'm confused.

1. I want to pass these variables as a macro parameter (PreA1C,  PostA1C,   chang_HgA1C; Pregluc, Postgluc,chang_gluc). 

 

2. Then I want to create 2 datasets where the patients in dataset1 are only people with a Pre A1c >=6.0 and the 2nd dataset has only those with glucose of >=140.

%MACRO mymacro(preaic, postaic,chng_aic,pregluc, postgluc,chang_gluc);
%let inputif = if  preaic  ge 6.0;  
%let inputif = if pregluc ge 140; 
%MEND;

# Calling a Macro program.
%mymacro(indatadef1, preaic, postaic,chng_aic, out1)
%mymacro(indatadef1, pregluc, postgluc,chang_gluc, out2)

3. What does call a macro 2 times mean?

Please I'd be glad to get inputs. Online resources have not been helpful.

2 REPLIES 2
ballardw
Super User

You example does not do anything. There is no data set mentioned anywhere. There is no place that any value is used to select records from a data set and no place that the other variables are mentioned.

 

You would have to provide the name of a data set to apply the "if" clause to. Since you say there would be two data sets then it makes sense to have two calls to a macro because you likely need to to call it for each separate data set.

 

Before writing any macro you have to have to have working basic not macro code to model the macro on and identify the parts you need to use. Do you have such code already written? If so, show that. If not, write it and then we discuss how to create such a macro.

Kurt_Bremser
Super User
%MACRO mymacro(preaic, postaic,chng_aic,pregluc, postgluc,chang_gluc);
/* you define a macro with 4 parameters, none of which is ever referenced in the macro */
/* keep in mind that macro variables or parameters need to be addressed as &name (leading ampersand) */
%let inputif = if  preaic  ge 6.0;
/* here you define a macro variable inputif, which is most likely local to the macro and will vanish once it finishes */
%let inputif = if pregluc ge 140; 
/* here you redefine the variable mentioned above */
%MEND;
/* since no code was generated, this macro does in essence nothing */

Macro language is a code generator; if you don't create code with it, it does not do anything.

Before engaging in ANY macro programming, solve your issue first with non-macro code; at least for a single instance, which you can then make dynamic.

If you're not yet able to solve your issue without a macro, then it is much too early to even think about macro coding, as it is a sign that you are not yet familiar enough with Base (non-macro) SAS coding.

See Maxim 11.

 

You want to create 2 datasets. Please give us an example of your existing data, and show what you want to get out of it. Provide your existing data in a data step with DATALINES, so we can easily recreate your dataset as is.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 702 views
  • 2 likes
  • 3 in conversation