DATA Step, Macro, Functions and more

Transpose a single column.

Reply
N/A
Posts: 0

Transpose a single column.

My table has only one variable, Var1, with 3 observations. The table looks like this:

Var1
qwer
asdf
zxcv

I want the table to have one single row(observation) like this:

Col1 Col2 Col3
qwer asdf zxcv

I have tried with PROC TRANSPOSE in different ways, but haven't succeeded.

The examples I have found are more complicated and can't be applied to this simple situation.

Susan
Super User
Posts: 5,256

Re: Transpose a single column.

Do you want a generic solution that will transpose all rows in table independent of number of rows? If you just want to transpose this three row table, just use a data step with assignment statements and explicit output. A generic solution would contain a step the figure out number of rows, and building an array to assign the row values to.

Maybe you could use PROC TRANSPOSE, but I'm always find myself frustrated when using it, because I can't understand how the different options/statements interact, it feels less logical to me than other procedures.

/Linus
Data never sleeps
N/A
Posts: 0

Re: Transpose a single column.

I am almost new to SAS.

I know the number of rows(observations of Var1) in my one column table, but I don't know the values in advance.

I don't think there are any indexes on a variable in a SAS table.

If it had been, I could have assigned Col1=Var1(1); Col2=Var1(2); Col3=Var1(3);.

Susan
Frequent Contributor
Posts: 82

Re: Transpose a single column.

Simple code that works:

data have;
input Var1 $;
datalines;
qwer
asdf
zxcv
;
run;

proc transpose data=have out=want (drop=_name_);
var var1;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Transpose a single column.

When you truly have a code problem, it is best to share the SAS code attempted and ideally any SAS log output with PUTLOG and other pertinent output diagnostics for forum subscriber feedback. Since attachments are not permitted, you can paste data/information directly into you forum post/reply as a communication means.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Transpose a single column.

Thank you very much, ieva.

I "knew" it had to be a simple solution.

Susan
Ask a Question
Discussion stats
  • 5 replies
  • 397 views
  • 0 likes
  • 4 in conversation