BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
3 REPLIES 3
LawrenceHW
Quartz | Level 8
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
Cynthia_sas
Diamond | Level 26
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=;) 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]
deleted_user
Not applicable
Thank you very much!!

I will try your solutions

Javi.

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

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 1566 views
  • 0 likes
  • 3 in conversation