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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.