Original Request:
You want to take your columns and turn them into rows. For example, you have a column called ODBC that you want displayed as a row - correct?
You have 35 columns, but how many rows in the current file?
This was pretty tricky - please give it a try, but beware of requirements.
Requirements:
- all fields must be character values; and the data can not have spaces
- first column values becomes the new column titles
- all other column values become row titles
- you need to pre-build a table layout to read the DISPLAY results from alternate log transpose_temp.log and it must have a field call field_names - which is the field names.
- you will have to use the Data Definition Wizard to define the layout for the results (a delimited file called transpose.log)
Requires two scripts Transpose_start and Transpose_Finish
Transpose_Start
Comment ***** transposes any file - using the values for:
Comment ***** the 1st field as the Columns names in the new file; and
Comment ***** the values of the other columns as the Rows in the new file
Comment *****
Comment ***** Notes:
Comment ***** All fields must be character type and the data can not have spaces
Comment ***** Requires an existing table layout (Transpose_temp) to read the DISPLAY results from alternate log transpose_temp.log and it must have a field call field_names - which is the field names.
Comment ***** Requires user to use Data Definition Wizard to define layout for reults - a delimited file called tranpose.log
Comment ***** written by CAATS 2008
set safety off
DIALOG (DIALOG TITLE "User Dialog" WIDTH 443 HEIGHT 315 ) (BUTTONSET TITLE "&OK;&Cancel" AT 348 12 DEFAULT 1 ) (TEXT TITLE "Select table to open" AT 60 52 ) (ITEM TITLE "f" TO "v_infile" AT 84 108 WIDTH 196 HEIGHT 159 ) (TEXT TITLE "cc CAATS 2008" AT 264 268 )
OPEN %v_infile%
delete transpose.log ok
delete transpose_temp.lix ok
delete transpose_temp.log ok
Comment **** Get names for new rows from column titles
Set log transpose_temp
Display
set log
OPEN transpose_temp
row_flag='N'
v_ctr=0
Row_list1=blanks(20000)
col_name=blanks(64)
GROUP if find('@ set')
row_flag='N'
Else if find('start len')
row_flag='Y'
Else if row_flag='Y'
Row_list1=alltrim(row_list1)+';'+alltrim(field_name) if v_ctr>=1
col_name=alltrim(field_name) if v_ctr=0
v_ctr=v_ctr+1
end
row_list=alltrim(substr(row_list1,2,20000))
v_field_no=v_ctr
Comment **** get names for new columns from first column values
OPEN %v_infile%
Col_list1=blanks(20000)
GROUP
Col_list1=alltrim(Col_list1)+';'+alltrim(%col_name%)
End
col_list=alltrim(substr(col_list1,2,20000))
export 'Type;'+col_list to transpose.log while recno()=1
OPEN Transpose_temp
COUNT
close
v_ctr=1
DO Transpose_Finish while v_ctr
delete transpose_temp.lix ok
delete transpose_temp.log ok
set safety on
Transpose_Finish
Comment ***** build strings of values for each column to be used as row values
temp=split(row_list,';',%v_ctr%)
Temp1=alltrim("%temp%")+';'+blanks(20000)
Open %v_infile%
group
Temp1=alltrim(temp1)+alltrim(%temp%)+';'
end
Export temp1 to transpose.log append while recno()=1
v_ctr=v_ctr+1
I realize that it means you will have to build a table layout to read the alternate log - the first time, but (given the work I put into this) can you give it a try.