cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • See how to interactively organize and restructure data for analysis. Register for May 29 webinar, 2pm US ET.

Discussions

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

Select columns from a data table based on rows from another data table.

I have 2 data tables and I want to use one to create a subset from the other.  One table has a series of columns and the filter table has those column names of interest listed as cells (rows) on another table.  I tried to use nested loops to get the subset but I get persistent errors.


Slán



SpannerHead
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Select columns from a data table based on rows from another data table.

Can you provide example tables and an example of what you wish to do?

 

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt2 = New Table("Untitled",
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"age", "sex"}))
);

cols = dt2[0, 1];

dt_subset = dt << Subset(All rows, columns(Eval(cols)));

jthi_0-1733947934280.png

 

-Jarmo

View solution in original post

shampton82
Level VII

Re: Select columns from a data table based on rows from another data table.

Oh, try this!  I had the same need I believe:

names default to here(1);

nw=newwindow("Select tables and column",show menu(0),
				Hlistbox(
					Panelbox("Data Table to select columns",
						lb1=listbox(get data table list ())
					),
					Panelbox("data table to select rows",
						vlistbox(
								lb2=listbox(get data table list ()),
								clb1=collistbox(),
								button box("press to get columns", dtname2=lb2 << Get Selected; names = datatable(dtname2[1]) << Get Column names; clb1 << append (names);),
								button box("press to select columns",col=clb1 << Get Selected; colist=column(datatable(dtname2[1]),col)<< GetValues(Format());
																	dtname1=lb1 << Get Selected; 
																	colqty=datatable(dtname1[1])<<get column names("string");
																	for(i=1, i<= nitems(colqty),i++,
																			for(j=1, j<=n items(colist),j++,
																				print(colqty[i],colist[j]);
																				if(colqty[i]==colist[j],
																						column(datatable(dtname1[1]),colist[j])<< Set Selected( 1 );
																						j=1;
																						break();
																					
																				);
																			
																			);
																		
																	);
																	
															
							
										)
						)
						
					)
				)
);

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Select columns from a data table based on rows from another data table.

Can you provide example tables and an example of what you wish to do?

 

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt2 = New Table("Untitled",
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"age", "sex"}))
);

cols = dt2[0, 1];

dt_subset = dt << Subset(All rows, columns(Eval(cols)));

jthi_0-1733947934280.png

 

-Jarmo
shampton82
Level VII

Re: Select columns from a data table based on rows from another data table.

Oh, try this!  I had the same need I believe:

names default to here(1);

nw=newwindow("Select tables and column",show menu(0),
				Hlistbox(
					Panelbox("Data Table to select columns",
						lb1=listbox(get data table list ())
					),
					Panelbox("data table to select rows",
						vlistbox(
								lb2=listbox(get data table list ()),
								clb1=collistbox(),
								button box("press to get columns", dtname2=lb2 << Get Selected; names = datatable(dtname2[1]) << Get Column names; clb1 << append (names);),
								button box("press to select columns",col=clb1 << Get Selected; colist=column(datatable(dtname2[1]),col)<< GetValues(Format());
																	dtname1=lb1 << Get Selected; 
																	colqty=datatable(dtname1[1])<<get column names("string");
																	for(i=1, i<= nitems(colqty),i++,
																			for(j=1, j<=n items(colist),j++,
																				print(colqty[i],colist[j]);
																				if(colqty[i]==colist[j],
																						column(datatable(dtname1[1]),colist[j])<< Set Selected( 1 );
																						j=1;
																						break();
																					
																				);
																			
																			);
																		
																	);
																	
															
							
										)
						)
						
					)
				)
);
SpannerHead
Level VI

Re: Select columns from a data table based on rows from another data table.

shampton82 thanks, script is great altogether.


Slán



SpannerHead

Recommended Articles