It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Highlighted
PS
PS
Level III

Word () function giving the wrong output

Hello 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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Word () function giving the wrong output

I 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"));
);
Jim

View solution in original post

5 REPLIES 5
Highlighted
txnelson
Super User

Re: Word () function giving the wrong output

Your 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], ","));
);
Jim
Highlighted
PS
PS
Level III

Re: Word () function giving the wrong output

Oh, my apologies. I used the expression:

For(nn=2, nn <= N items (line_content), nn++,
  Col1_list[nn-1]=Word(1,line_content[nn], ",");
  Col2_list[nn-1]=Word(2,line_content[nn], ",");
);

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.

 

 

Editor.PNGExcel.PNGNotepadplusplus.PNGEditor 2.PNG

Highlighted
PS
PS
Level III

Re: Word () function giving the wrong output

Here is the original csv attached. I had my colleague look over the shoulder, he saw it too... It is reproducible.

Highlighted
txnelson
Super User

Re: Word () function giving the wrong output

I 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"));
);
Jim

View solution in original post

Highlighted
PS
PS
Level III

Re: Word () function giving the wrong output

Thanks 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.
Article Labels

    There are no labels assigned to this post.