BookmarkSubscribeRSS Feed
Jens89
Obsidian | Level 7

When I'm transposing, I want my column names to be a merged version of 2 separate columns.

 

Column 1: is called "Topic", example: Cars per household

Column 2: is called "Variable", example: 3

 

When I transpose I want to merge these two columns and as a result have something like "Cars per household : 3"

Both column names are of the type character.

 

I've tried something like 

 

transpose data = mydataset out = transposed_data;

id Topic:Variable;

run;

 

but that doesn't run which I expected.

1 REPLY 1
ballardw
Super User

@Jens89 wrote:

When I'm transposing, I want my column names to be a merged version of 2 separate columns.

 

Column 1: is called "Topic", example: Cars per household

Column 2: is called "Variable", example: 3

 

When I transpose I want to merge these two columns and as a result have something like "Cars per household : 3"

Both column names are of the type character.

 

I've tried something like 

 

transpose data = mydataset out = transposed_data;

id Topic:Variable;

run;

 

but that doesn't run which I expected.


 

did you try

 

ID topic variable;

 

Note: this will not be valid if Topic values are numeric or text starting with a digit as SAS variable names don't allow digits in the first position. Reverse the order of the variables if this is the case.

Also if the combinations of the ID variables could result in the same value such as

Var1 Var2

AB   CD

A      BCD

would both attempt to create a variable "ABCD" would be invalid.

 

Example with a data set you should have available:

proc transpose data=sashelp.class
   out=work.trans
   ;
id name age;
run;

 

 

Otherwise post example data and what you want for output from that example data. It isn't clear if you have an existing "variable" named variable or not.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 499 views
  • 0 likes
  • 2 in conversation