BookmarkSubscribeRSS Feed
ENTHU

Contributor

Joined:

May 13, 2018

How to save a list to a csv?

Trying to save a list to a column in csv.How to do this?

Tried the follwoing code but doesnt seem to work- 

name = {};
name =Name1||"_"||Name2;

Macrodt=New Table("table1",
New Column("name",
Character,
Nominal
Set Values( {name [1]})
),
invisible
);

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Re: How to save a list to a csv?

You are setting the variable name to be a list

name = {}'

But then you set it to be a string variable

name = Name1 || "_" || Name2.;

So name is no longer a list.

Below is a modification to your code that does what I think you want

name = {};
name1 = "a";
name2 = "b";
name[1] = Name1 || "_" || Name2;
Macrodt = New Table( "table1",
	New Column( "name", Character, 
	Nominal, Values( Eval( name ) ) )
);
Jim
2 REPLIES
Highlighted
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Re: How to save a list to a csv?

You are setting the variable name to be a list

name = {}'

But then you set it to be a string variable

name = Name1 || "_" || Name2.;

So name is no longer a list.

Below is a modification to your code that does what I think you want

name = {};
name1 = "a";
name2 = "b";
name[1] = Name1 || "_" || Name2;
Macrodt = New Table( "table1",
	New Column( "name", Character, 
	Nominal, Values( Eval( name ) ) )
);
Jim
pmroz

Super User

Joined:

Jun 23, 2011

Re: How to save a list to a csv?

A common mistake is to use the same name for a variable and a column.  Your list is called name, and you are defining a column called name.  Try this code instead.  I removed invisible so you can see the result.

name1 = "a";
name2 = "b";
name_list = {};
name_list[1] = Name1||"_"||Name2;
Macrodt=New Table("table1",
	New Column("name", Character, Nominal, Set Values( name_list) ),
);