Help using Base SAS procedures

Using MACRO without defining one of the macro variables?

Reply
Occasional Contributor
Posts: 15

Using MACRO without defining one of the macro variables?

I have a macro that is being run on several different user IDs, but I'd like to run the macro on the entire population as well. Right now, the macro call uses the following variables:

USER ID
VAR1
VAR2
DATE1
DATE2

I'd like to run the macro on ALL USER IDs, so instead of my macro call being:
%MACRO(132, ABC, DEF, JAN, FEB) what would I do to get it to run on all USER IDs?
Super User
Posts: 19,867

Re: Using MACRO without defining one of the macro variables?

Posted in reply to JonathanWarrick
Depends on how you want to call it and what your macro does...

1. Change your macro so that the first parameter is handled as a variable list
2. Create another macro that loops through your list of ids in a dataset and calls the macro.


If you may want to do a few ID's at a time rather than a whole dataset you may want to consider 1 as the most viable option.
Super User
Posts: 10,044

Re: Using MACRO without defining one of the macro variables?

Posted in reply to JonathanWarrick
Another Choice is to use call execute() ----My favorite.
Which can generate code dynamically with your dataset.
But firstly you need to transpose this dataset with proc transpose.


Ksharp
Valued Guide
Posts: 2,177

Re: Using MACRO without defining one of the macro variables?

Posted in reply to JonathanWarrick
my toolbag carries a macro I use for situations like this. I even presented it at a SAS conference
"make light work of list processing"
http://www2.sas.com/proceedings/sugi31/012-31.pdf
Occasional Contributor
Posts: 15

Re: Using MACRO without defining one of the macro variables?

Posted in reply to JonathanWarrick
Is there a way to set the USER ID to a default value so that every single record has that value (basically making that field irrelevant) so I can run the macro on every single record? I tried using the following code to do this, but I'm getting this error:

%MACRO NAME(NAME,ID);

%MACRO MONTH(month);

data &NAME._&month.;
set all_&month._nores;
%if "&NAME." eq "CONS" %then %do;
USER_ID eq '888888888';
%end;
run;

data &NAME._&month.;
set &NAME._&month.;
if USER_ID eq &ID.;
run;

%MEND MONTH;

%MONTH(&cur_month.);
%MONTH(&prev_month1.);
%MONTH(&prev_month2.);
%MONTH(&prev_month3.);
%MONTH(&prev_month4.);
%MONTH(&prev_month5.);

run;

(it continues for a while, but the rest is unnecessary)


Here are a few of the Macro calls:

%NAME(CONS,'888888888');
%NAME(AH,'904029181');
%NAME(BU,'903769181');


Here is the log/error:

1705 %NAME(CONS,'888888888');
NOTE: Line generated by the invoked macro "MONTH".
3 USER_ID eq '888888888';
-----------------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CONS_APR11 may be incomplete. When this step was stopped there were 0
observations and 82 variables.
NOTE: DATA statement used (Total process time):
real time 0.21 seconds
cpu time 0.01 seconds




NOTE: There were 0 observations read from the data set WORK.CONS_APR11.
NOTE: The data set WORK.CONS_APR11 has 0 observations and 82 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Super User
Posts: 11,343

Re: Using MACRO without defining one of the macro variables?

Posted in reply to JonathanWarrick
I think you meant:

%if "&NAME." eq "CONS" %then %do;
USER_ID = '888888888'; /*assignment*/
%end;

instead of
%if "&NAME." eq "CONS" %then %do;
USER_ID eq '888888888'; /*comparison*/
%end;
Occasional Contributor
Posts: 15

Re: Using MACRO without defining one of the macro variables?

Yup, that was the problem! Stupid mistake - thanks for pointing it out!
Ask a Question
Discussion stats
  • 6 replies
  • 212 views
  • 0 likes
  • 5 in conversation