BookmarkSubscribeRSS Feed
King
Calcite | Level 5

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

3 REPLIES 3
art297
Opal | Level 21

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

;

Domenico
Fluorite | Level 6

Hi Art,

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

Thanks for that

Ksharp
Super User

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2916 views
  • 1 like
  • 4 in conversation