Hi everyone,
I have a text data file generated by a scanning application (REMARK) that has two record types however both record types currently are represented by the same value. i.e
11001325445
110013
110014
The first line is the questionnaire record and the 2nd and third lines are the person records. How can I modify the record type value to match the dictionary (1 for questionnaire and 2 for person)?
Modify record type
-
- Posts: 1882
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Modify record type
If you are trying to do this in CSPro, you'll have to manipulate the data file using CSPro's file functions. First, you need to come up with a way to determine what lines are questionnaire records vs. person records. Perhaps the length of the record will tell you, or perhaps the order of the records will tell you.
For example, if you know that there is always one questionnaire record, and then multiple person records, and that the questionnaire record appears first, you could read line-by-line, see when the case IDs change, and then process records accordingly.
Here is an example of that:
For example, if you know that there is always one questionnaire record, and then multiple person records, and that the questionnaire record appears first, you could read line-by-line, see when the case IDs change, and then process records accordingly.
Here is an example of that:
File data_in;
File data_out;
data_in.open("data-in.dat");
data_out.open("data-out.dat", create);
string line;
string last_id;
while data_in.read(line) do
// assume that the case IDs (key) start at position and are of length 4
string this_id = line[2:4];
// if the ID matches that of the previous line, then change the record type to 2
if this_id = last_id then
line[1:1] = "2";
// otherwise we assume this is the first line of a new case and we keep the record type as 1
else
last_id = this_id;
endif;
data_out.write(line);
enddo;
When run on your data, it becomes:File data_out;
data_in.open("data-in.dat");
data_out.open("data-out.dat", create);
string line;
string last_id;
while data_in.read(line) do
// assume that the case IDs (key) start at position and are of length 4
string this_id = line[2:4];
// if the ID matches that of the previous line, then change the record type to 2
if this_id = last_id then
line[1:1] = "2";
// otherwise we assume this is the first line of a new case and we keep the record type as 1
else
last_id = this_id;
endif;
data_out.write(line);
enddo;
11001325445
210013
210014