MACROS with variable number of parametres.

Reply
N/A
Posts: 0

MACROS with variable number of parametres.

Hi!

I will like to know if it's possible to program a MACRO with a variable number of parametres, and if it's possible how can I do it.

I am trying to order a DATASET with PROC SORT and I need that the variables by which I am ordering the dataset could be variable, in number and in value.

Sorry for my English.

Regards.
Contributor
Posts: 49

Re: MACROS with variable number of parametres.

Javi,

The best way of achieving this is have a macro variable which is a list of data set variables (i.e. SortOrder=var1 var2 var3).

If you want to be a bit more dynamic then you probably need to utilise the metadata available about data sets (using PROC CONTENTS or the SASHELP data views) to find out what variables exist on data sets.

Hope this helps,
Lawrence
SAS Super FREQ
Posts: 8,816

Re: MACROS with variable number of parametres.

Javi:
Another point to add to Lawrence's answer is that if a macro variable has no value, when substitution is done, you could consider it to be the same as adding a blank or hit on the space bar to your code.

The first time this Proc Sort is invoked, there is no value for var3 (%let var3=Smiley Wink so the data is only sorted by region and subsidiary. For the second Proc Sort, all 3 macro variables have a value, so the data is sorted by all 3 variables.

cynthia

[pre]
options mprint mlogic symbolgen;
%let var1 = region;
%let var2 = subsidiary;
%let var3 =;
proc sort data=sashelp.shoes out=shoes1;
by &var1 &var2 &var3;
run;

options mprint mlogic symbolgen;
%let var1 = product;
%let var2 = region;
%let var3 =subsidiary;
proc sort data=sashelp.shoes out=shoes2;
by &var1 &var2 &var3;
run;

[/pre]
N/A
Posts: 0

Re: MACROS with variable number of parametres.

Thank you very much!!

I will try your solutions

Javi.
Ask a Question
Discussion stats
  • 3 replies
  • 400 views
  • 0 likes
  • 3 in conversation