BookmarkSubscribe
Choose Language Hide Translation Bar
ENTHU
Community Trekker

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
);

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

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
0 Kudos
2 REPLIES 2
Highlighted
txnelson
Super User

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
0 Kudos
pmroz
Super User

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) ),
);
0 Kudos