DATA Step, Macro, Functions and more

Reorder SAS variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 330
Accepted Solution

Reorder SAS variables

Hi Everyone,

I have a data file like

 

data have;

input var x_1 x_3 x_bac x_1dnx b ;

datalines;

0 1 1 1 1 0

;

run;

 

I want to put all X_ to the end, since there are hundred of X_ variable and they follow no rule other than the prefix of X_, is there any way to do it quicky?

 

 

Thank you,

 

HHC


Accepted Solutions
Highlighted
Solution
2 weeks ago
Respected Advisor
Posts: 3,734

Re: Reorder SAS variables

data reorder;
   if 0 then set have(drop=x_:);
   set have;
   run;

View solution in original post


All Replies
Highlighted
Solution
2 weeks ago
Respected Advisor
Posts: 3,734

Re: Reorder SAS variables

data reorder;
   if 0 then set have(drop=x_:);
   set have;
   run;
Regular Contributor
Posts: 190

Re: Reorder SAS variables

@data_null__ very cool solution Smiley Happy

 

Just to understand, when we use the if 0 trick, we make sure that whatever follows is only done in compilation right?

Respected Advisor
Posts: 3,734

Re: Reorder SAS variables


draycut wrote:

@data_null__ very cool solution Smiley Happy

 

Just to understand, when we use the if 0 trick, we make sure that whatever follows is only done in compilation right?


Correct.

Super Contributor
Posts: 330

Re: Reorder SAS variables

Hi Data_null_,
Interesting indeed!
But what does the "if 0" do to the code?
Thank you,
HHC
Respected Advisor
Posts: 3,734

Re: Reorder SAS variables


hhchenfx wrote:
Hi Data_null_,
Interesting indeed!
But what does the "if 0" do to the code?
Thank you,
HHC

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p1d61passkeqo0n1jdn0...

 

It is an expression that is FALSE preventing the SET statement from being executed.  The SET statement is compiled which places variables in the PDV in the desired order.

Super Contributor
Posts: 330

Re: Reorder SAS variables

Thank you for your help!

HHC

Post a Question
Discussion Stats
  • 6 replies
  • 178 views
  • 8 likes
  • 3 in conversation