Word () function giving the wrong outputHello all,
I am having trouble using the word() function. I start with a .csv
for example:
col1,col2
0,556
0,557
0,558
-1,225
-1,226
Datafile = Load Text File (...);
line_content = Words (Datafile, "\!n");
For(nn=2, nn <= N items (line_content), nn++,
Col1_list=Word(1,line_content[nn], ",");
Col2_list=Word(2,line_content[nn], ",");
);
The resulting lists are:
{"0", "0", "0", "-12", "-12"}
{"556", "557", "558", "25", "26"}
hence the word() function works differently if the line starts with a minus... I have tried Item () and using a Num(Word()) clause, but it does not change anything. I have also tried Word(1,Trim(line_content[nn],",")).
I am using JMP 14.0.0
Thanks in advance
Re: Word () function giving the wrong outputThanks again for your ideas. This looks good too. I have no idea what changed, but JMP now imports the files correctly with the script from yesterday when I initially posted the question (except for the error I made here in the post). There must be some higher level windows/excel setting mix up between "," and "." decimal/point differentiation. I have configured my german windows to use the american standard.Re: Word () function giving the wrong outputI am not exactly sure what you are now looking for, but the little script below reads in your .csv file and returns the 2 lists you specified, without error. The only item I added, was to make sure that any Carriage Return characters that exist in the file are not included into the values of the lists.
names default to here(1);
Datafile = Load Text File ("...……...\WFR1_sample1.csv");
line_content = Words (Datafile, "\!n");
// Get rid of all lines upto the Graph data
// The \!r is a Carriage Return character which is at the end of each line
line_content = remove(line_content,1,loc(line_content,"{QgWave Graphs}\!r")+1);
Col1_list = {};
Col2_list = {};
For(nn=1, nn <= N items (line_content), nn++,
insert into(Col1_list,Word(1,line_content[nn], ",\!r"));
insert into(Col2_list,Word(2,line_content[nn], ",\!r"));
);Re: Word () function giving the wrong outputHere is the original csv attached. I had my colleague look over the shoulder, he saw it too... It is reproducible.
Re: Word () function giving the wrong outputOh, my apologies. I used the expression:
<SPAN class="token function">For</SPAN><SPAN class="token punctuation">(</SPAN>nn<SPAN class="token operator">=</SPAN><SPAN class="token number">2</SPAN><SPAN class="token punctuation">,</SPAN> nn <SPAN class="token operator"><=</SPAN> N items <SPAN class="token punctuation">(</SPAN>line_content<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN> nn<SPAN class="token operator">++</SPAN><SPAN class="token punctuation">,</SPAN>
Col1_list[nn-1]<SPAN class="token operator">=</SPAN><SPAN class="token function">Word</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN>line_content<SPAN class="token punctuation">[</SPAN>nn<SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">,</SPAN> <SPAN class="token string">","</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
Col2_list[nn-1]<SPAN class="token operator">=</SPAN><SPAN class="token function">Word</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token number">2</SPAN><SPAN class="token punctuation">,</SPAN>line_content<SPAN class="token punctuation">[</SPAN>nn<SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">,</SPAN> <SPAN class="token string">","</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
I will switch to using the insert into () function, which is a lot more convenient. Thanks.
If i use the sample .csv you provided, the code works indeed.
But I just started questioning my mental health and opened the .csv files with different editors: Windows notepad, notepad++, Word Pad, Excel. Every few runs the displayed data columns will have the comma in a different place, independently of the programs used. I have never seen this before. I might just leave work and go home.




Re: Word () function giving the wrong outputYour syntax is suspect to me. I am not sure how you are creating your Col1_list and Col2_list would ever create a concatenated list. Below is my modification, and attached is the csv file that I used. It creates the 2 lists without error on JMP 14.1
Datafile = Load Text File (".................\test.csv");
line_content = Words (Datafile, "\!n");
Col1_list = {};
Col2_list = {};
For(nn=2, nn <= N items (line_content), nn++,
insert into(Col1_list,Word(1,line_content[nn], ","));
insert into(Col2_list,Word(2,line_content[nn], ","));
);