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

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
Barite | Level 11
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
Barite | Level 11

Thank you for your help!

HHC

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 6 replies
  • 1158 views
  • 8 likes
  • 3 in conversation