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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 915 views
  • 5 likes
  • 3 in conversation