BookmarkSubscribeRSS Feed
ubshams
Quartz | Level 8

my data set has following variables

x1 x2 x3 x4....x100 Month

 

How do I rearrange so that the following happens:

Month x1 x2 x3 x4....x100

 

In other words I need to rearrange so that Month is the first column. But I don't want to have to write down all other

100 variables (i actually have over 7,000 variables).

 

Thanks in advance!

 

 

2 REPLIES 2
Reeza
Super User

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

data want;
retain month x1-x100;
set have;
run;

@ubshams wrote:

my data set has following variables

x1 x2 x3 x4....x100 Month

 

How do I rearrange so that the following happens:

Month x1 x2 x3 x4....x100

 

In other words I need to rearrange so that Month is the first column. But I don't want to have to write down all other

100 variables (i actually have over 7,000 variables).

 

Thanks in advance!

 

 


 

Astounding
PROC Star

With 7,000 variables, I'm imagining that they are not necessarily named x1-x7000.  You can shortcut the code and move MONTH to the first position just using:

data want;
retain month;
set have;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 636 views
  • 5 likes
  • 3 in conversation