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
SAS Super FREQ
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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