BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
data reorder;
   if 0 then set have(drop=x_:);
   set have;
   run;

View solution in original post

6 REPLIES 6
data_null__
Jade | Level 19
data reorder;
   if 0 then set have(drop=x_:);
   set have;
   run;
PeterClemmensen
Tourmaline | Level 20

@data_null__ very cool solution 🙂

 

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

data_null__
Jade | Level 19

@PeterClemmensen wrote:

@data_null__ very cool solution 🙂

 

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


Correct.

hhchenfx
Rhodochrosite | Level 12
Hi Data_null_,
Interesting indeed!
But what does the "if 0" do to the code?
Thank you,
HHC
data_null__
Jade | Level 19

@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.

hhchenfx
Rhodochrosite | Level 12

Thank you for your help!

HHC

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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