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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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