1

My table has only 1 row and many columns. I need to return only 1 column and many rows. It is possible to do a transpose via SAS SQL?

Before:

column1 column2 column3 column4
   1       2       3       4

After:

column
   1
   2
   3
   4
Nick
  • 7,103
  • 2
  • 21
  • 43
Keliimek
  • 155
  • 1
  • 1
  • 10
  • Not a simple solution. SQL doesn't allow variable list short cuts. You should use proc transpose. If you insist on SQL then you'll need a macro to first determine the number of columns and then generate your union statements dynamically. I don't think it's worth the effort personally. – Reeza Nov 03 '16 at 20:47

2 Answers2

0

Since you mention SAS SQL (as opposed to any other SAS proc), this is a solution, though it will be a bit verbose if you have a lot of columns:

PROC SQL;

    SELECT column1 AS column FROM table
    UNION ALL
    SELECT column2 AS column FROM table
    UNION ALL
    SELECT column3 AS column FROM table
    UNION ALL
    SELECT column4 AS column FROM table;

    /* Add for each column */

QUIT;

This simply unions (stacks) each column.

Nick
  • 7,103
  • 2
  • 21
  • 43
0

Why not use PROC TRANSPOSE you don't have to know how many columns or even the names PROC TRANSPOSE will transpose all numeric columns by default.

proc transpose data= out= ;
   run;
data _null_
  • 8,534
  • 12
  • 14