cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
davidk
Level I

Transposing a comma-separated string into a column in JSL

Hi folks,

I am want to transform a string that i am getting as an input from a text edit box such as a,b,c,d... into a column:

a

b

c

d

...

Any ideas?

Thanks,

David

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Transposing a comma-separated string into a column in JSL

You can use the WORDS function to parse the string into a list, and then add it as a new column.

a = words("a,b,c,d,e", ",");

n = nitems(a);

dt = new table("Untitled", add rows(n),

        new column("My List", character, nominal, set values(a)));

View solution in original post

4 REPLIES 4
pmroz
Super User

Re: Transposing a comma-separated string into a column in JSL

You can use the WORDS function to parse the string into a list, and then add it as a new column.

a = words("a,b,c,d,e", ",");

n = nitems(a);

dt = new table("Untitled", add rows(n),

        new column("My List", character, nominal, set values(a)));

davidk
Level I

Re: Transposing a comma-separated string into a column in JSL

This is exactly what i was looking for, thanks a bunch!

Unfortunately, i cannot make the next step which i thought to be trivial.

How can the column you called "My List" be saved as a text file? I used various combinations with the command save text file, but nothing worked. This is the only column in the data table, so saving the whole table would work as well.

pmroz
Super User

Re: Transposing a comma-separated string into a column in JSL

If all you want to do is save each entry in your original string into a separate line of a file, then there's a simpler way:

a = "a,b,c,d,e";

crlf = hextochar("0D") || hextochar("0A");

b = substitute(a, ",", crlf);

save text file("C:\b.txt", b);

davidk
Level I

Re: Transposing a comma-separated string into a column in JSL

Many thanks