Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
sbfernandes
Contributor III
Contributor III

Loading/Transposing data in row format from text file

Greetings

I am trying to load data from a text file. The Headers are in rows while data is in columns.

Below is the data in text file (also attached).

----------------------------FILE START--------------------------------------------------------------------------

SEQ | 1 | 2 | 3 |
Name | John | Steven | Mark |
Family Name | Happy | Glad | Sun |
ID | 111 | 222 | 333 |
| | | |
Gender | Male | Male | Male |
DOB | 020110 | 150211 | 221113 |

 

SEQ | 7 | 8 | 9 |
Name | mary | Hope | Lisa |
Family Name | Wilkins | Gladys | Sinter |
ID | 119 | 229 | 339 |
| | | |
Gender | FeMale | FeMale | FeMale |
DOB | 020110 | 150211 | 221113 |

 

 

 

SEQ | 10 |
Name | Susan |
Family Name | Marlb |
ID | 449 |
| |
Gender | FeMale |
DOB | 120114 |

--------------------------------------------------------FILE END------------------------------------------------------

Required table should look like

SEQNameFamily NameIDGenderDOB
1JohnHappy111Male020110
2StevenGlad222Male150211
3MarkSun333Male221113
7maryWilkins119FeMale020117
8HopeGladys229FeMale150218
9LisaSinter339FeMale221119
10SusanMarlb449FeMale120114
Labels (2)
2 Replies
chrismarlow
Specialist II
Specialist II

Hi,

Here is a start;

data:
LOAD
	If(RowNo()=1,1,If(@1='SEQ',Peek(RC)+1,Peek(RC))) AS RC,
	*;
LOAD @1, 
     @2, 
     @3, 
     @4
FROM
SampleInputFile.txt
(txt, codepage is 28591, no labels, delimiter is '|', msq);

seqmap:
CrossTable (TextField,SEQ,1) 
Load	
	RC,
	@2,
	@3,
	@4
RESIDENT data
WHERE @1='SEQ';


name:
CrossTable (TextField,Name,1) 
Load	
	RC,
	@2,
	@3,
	@4
RESIDENT data
WHERE @1='Name';

Left Join (seqmap)
LOAD
	*
Resident name;

DROP TABLES data, name;

You should be able to make copies & amend the code from 'name:' for each of your fields & you might need to add more to the DROP TABLES statement & possibly tidy up (you get some empty rows where you don't have 3 SEQs in a row).

Cheers,

Chris.

sbfernandes
Contributor III
Contributor III
Author

Hi Chrismarlow

Thanks for the suggestion. This would work for the sample file. However my actual data contains around 50 column headers (in rows)  and 10's of thousands of records.