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

Hello

I am using Proc Transpose from wide to long.

There are 2 things that I want to ask please:

question 1;

Why in the data set ttt2  column name is "X1"?

I want to call it "X

question 2:

I want to rename  Column _Name_ to  'date'

I want that values will be 

1909
1908
1907
1906
1905

 

and not 

X1909
X1908
X1907
X1906
X1905

 

Data ttt1;
Input ID X1909 X1908 X1907 X1906 X1905;
cards;
1 10 25 32 40 51
2 12 14 6 18 20
3 15 22 27 33 22
;
run;

/*ID date X*/
/*1  1909 10*/
/*1  1908 25*/
/*1  1907 32*/
/*1  1906 40*/
/*1  1905 51*/
/*2  1909 12*/
/*2  1908 14*/
/*2  1907 6*/
/*2  1906 18*/
/*2  1905 20*/
/*3  1909 15*/
/*3  1908 22*/
/*3  1907 27*/
/*3  1906 33*/
/*3  1905 22*/
 

proc transpose data =ttt1 out= ttt12  prefix=X;
by ID;
var X1909 X1908 X1907 X1906 X1905;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You can do the renaming like this

 

proc transpose data =ttt1 out= ttt12(rename=(_Name_=date));
by ID;
var X1909 X1908 X1907 X1906 X1905;
run;

As for removing the 'X'.. This is a data manipulation question. Not a job for PROC TRANSPOSE. i would simply add a data step

 

data ttt13;
    set ttt12;
    date=compress(date, , 'kd');
run;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

You can do the renaming like this

 

proc transpose data =ttt1 out= ttt12(rename=(_Name_=date));
by ID;
var X1909 X1908 X1907 X1906 X1905;
run;

As for removing the 'X'.. This is a data manipulation question. Not a job for PROC TRANSPOSE. i would simply add a data step

 

data ttt13;
    set ttt12;
    date=compress(date, , 'kd');
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 613 views
  • 1 like
  • 2 in conversation