DATA Step, Macro, Functions and more

Reorder SAS variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 412
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
Solution
‎02-06-2017 04:51 PM
Respected Advisor
Posts: 3,799

Re: Reorder SAS variables

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

View solution in original post


All Replies
Solution
‎02-06-2017 04:51 PM
Respected Advisor
Posts: 3,799

Re: Reorder SAS variables

data reorder;
   if 0 then set have(drop=x_:);
   set have;
   run;
PROC Star
Posts: 740

Re: Reorder SAS variables

Posted in reply to data_null__

@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,799

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: 412

Re: Reorder SAS variables

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

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: 412

Re: Reorder SAS variables

Posted in reply to data_null__

Thank you for your help!

HHC

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 396 views
  • 8 likes
  • 3 in conversation