cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
ileshem
Level III

Take value from specific cell to create a column

Hello, 

In JSL, I want to use a specific cell value to create a column. how can I do it?

From this:

ID 
1122 
NameAge
Johan23
David34
Jack27

to This: 

IDNameAge
1122Johan23
1122David34
1122Jack27
2 REPLIES 2
jthi
Super User

Re: Take value from specific cell to create a column

For this specific case this should work:

 

Names Default To Here(1);

dt = New Table("Untitled 5",
	Add Rows(6),
	Compress File When Saved(1),
	New Column("Column 1",
		Character,
		"Nominal",
		Set Values({"ID", "1122", "Name", "Johan", "David", "Jack"})
	),
	New Column("Column 2",
		Character(16),
		"Nominal",
		Set Values({"", "", "Age", "23", "34", "27"})
	)
);
wait(1);
//get column name
columnNameCell = dt[1,1];
//get cell value
valueCell = dt[2,1];
//Rename columns
Column(dt,1) << Set Name(dt[3,1]);
Column(dt,2) << Set Name(dt[3,2]);
//Remove extra rows
dt << Delete Rows([1,2,3]);
//create new column
dt << New Column(columnNameCell, Character, Nominal, << Set Each Value(valueCell));
//Move ID column
dt << Move Selected Columns(:ID, To First);

For modifications like this I think Data Table Subscripting is very helpful

 

-Jarmo
Craige_Hales
Super User

Re: Take value from specific cell to create a column

nice! I don't think I understood the question until I ran your answer a line at a time.

Craige

Recommended Articles