Help using Base SAS procedures

horizontal sort in row

Reply
Occasional Contributor
Posts: 7

horizontal sort in row

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

PROC Star
Posts: 7,357

horizontal sort in row

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

;

Occasional Contributor
Posts: 10

Re: horizontal sort in row

Hi Art,

excellente solution. Didn't know about the call routine sortn.
Very nice code and simple to understand.

Thanks for that

Super User
Posts: 9,671

Re: horizontal sort in row

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

Ask a Question
Discussion stats
  • 3 replies
  • 1173 views
  • 1 like
  • 4 in conversation