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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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