BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
5 REPLIES 5
LinusH
Tourmaline | Level 20
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
deleted_user
Not applicable
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
ieva
Pyrite | Level 9
Simple code that works:

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

proc transpose data=have out=want (drop=_name_);
var var1;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
Thank you very much, ieva.

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

Susan

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 2843 views
  • 0 likes
  • 4 in conversation