Hai,
please wite a macro to sort in horizontal way.
suppose
var1 var2 var3 var4 var5
1 20 7 2 6 resp
i want 1 2 6 7 20
If this is a homework assignment, the following probably won't be of much help. However, if it isn't, the easiest way to sort such variables is with an array. e.g.,
data have;
array vars(*) var1-var5;
input var1-var5;
call sortn(of vars(*));
cards;
1 20 7 2 6
;
Hi Art,
excellente solution. Didn't know about the call routine sortn.
Very nice code and simple to understand.
Thanks for that
Why do you want to use Macro?
There is no need to use Macro. Macro is only to use to substitute sas code.
data temp; input var1-var5; cards; 1 20 7 2 6 2 5 24 2 65 ; run; data _null_; set temp; array _var{*} var1 -var5; do i=1 to dim(_var); do j=i+1 to dim(_var); if _var{i} gt _var{j} then do; temp=_var{i}; _var{i}=_var{j}; _var{j}=temp; end; end; end; put _var{*}=; run;
Ksharp
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.