Previous Page | Next Page

Doing More with Data Management

Transposing a Table

You can use Transpose table under Utilities on the Data Management menu to invert a table. Transposing a table turns the rows of a table into columns and vice versa.

In this section, you first sort the ORANGES table in order of the store number because you group the transposed rows by store. Then you transpose the sorted table so that the price for the first variety of oranges becomes a row with a separate column for each day's price.

The following display shows a listing report of the ORANGES table before it is transposed.

Listing of ORANGES Table Before Transposing

[Listing of ORANGES Table Before Transposing]


Additional Information

For additional information, refer to "The TRANSPOSE Procedure" in the Base SAS Procedures Guide.


Instructions

  1. To display the Sort a Table window, follow this selection path:Tasks [arrow] Data Management [arrow] Sort

    Sort a Table Window

    [Sort a Table Window]

  2. Use the Table button to select the SASUSER.ORANGES table.

  3. Select Output table. The Specify Output Table window appears. The Specify Output Table is identical to the window shown in Output Table or View Window.

  4. In the Table field, type ORGSORT as the name of the output table.

    By leaving the default of Temporary, a temporary table is created in the WORK library. The WORK.ORGSORT table is deleted when you exit SAS. An indicator next to Temporary shows that this item is selected.

  5. Select OK to return to the Sort a Table window.

  6. Use the Sort by columns button to select the STORE column.

  7. Select OK to return to the Sort a Table window.

  8. To sort the table, follow this selection path:Run [arrow] SubmitA message appears to indicate that the table was successfully sorted.

  9. Select Goback.

  10. Follow this selection path to open the Transpose a Table window:Tasks [arrow] Data Management [arrow] Utilities [arrow] Transpose TableThe Transpose a table window appears.

    Transpose a Table Window

    [Transpose a Table Window]

  11. The WORK.ORGSORT table should already be listed for Table. If not, use the Table button to select the WORK.ORGSORT table.

  12. Select Output table. The Specify Output Table window appears.

  13. In the Table field, type ORGTRANS as the name of the output table, then select OK to return to the Transpose a Table window.

    By leaving the default of Temporary, a temporary table is created in the WORK library. The WORK.ORGTRANS table is deleted when you exit SAS. An indicator next to Temporary shows that this item is selected.

  14. Use the Columns to be transposed button to select the PRICE1 column as the column to be transposed (that is, changed to a row).

  15. Select Additional options. The Additional Transpose Options window appears.

    Additional Transpose Options Window

    [Additional Transpose Options Window]

  16. Use the Group the transposed rows button to select the STORE column as the column you want to use as a grouping column.

  17. Use the column to be used to label transposed columns button to select the DAY column as the label you want to use to label the columns of the transposed data in the ORGTRANS output table.

    SAS generates a row for each column that is being transposed for each group.

  18. In the Additional Transpose Options window, position the cursor in the Prefix field and type Day as the prefix to each number that represents a day of the week.

    Make sure each formatted value of the DAY column occurs only once in each group of the active table. Duplicate values produce a warning message in the LOG window and stop the procedure.

  19. Select OK to return to the Transpose a Table window.

  20. To transpose the table, follow this selection path:Run [arrow] SubmitA message appears asking if you want to view the transposed table. Select OK, then Goback. The transposed table appears in an FSVIEW window.

    Transposed Table

    [Transposed Table]

    Use the scroll bars or the RIGHT command or function key to display the rest of the transposed data.

  21. To exit the FSVIEW window, follow this selection path:File [arrow] Close

Previous Page | Next Page | Top of Page