cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
AT
AT
Level V

A variable in a loop

Hi,

I like to replace the values for

Column Names Start(2),

Data Starts( 3 ) );

 

as a variable like Headstart=2, DataStart=3 in Column Names Start(HeadStart). I used

Eval(Parse( " Column Names Start("||HeadStart||"),"  ));

I get no error but the results are not correct.

I appreciate your help. Thanks

----------------------------------------------------------------

For( iii = 1, iii <= nf, iii++, //this starts the first loop

 

filenow = (filelist[iii]);

dt = Open( filenow, private,

Column Names Start(2),

Data Starts( 3 ) );

 

New Column( "Source", Character, Nominal );

:Source << set each value( filenow );

//dt<<new column("Source", character, nominal)<<set each value(9999);

dt << Run Formulas();

//add the current table to the bottom of the combined data table

cctable << Concatenate( Data Table( dt ), Append to first table );

//don't use "Create Source Column" argument

Close( dt, NoSave );//after concatenating the table, close it and move on

);//end of the first for loop

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: A variable in a loop

I would put the open into Substitution() structure to make the changes and to run the code

datastart = 2;
namestart = 1;

Eval(
	Substitute(
			Expr(
				Open(
					"C:\...\simple.txt",
					columns(
						New Column( "1", Numeric, "Continuous", Format( "Best", 12 ) ),
						New Column( "2", Numeric, "Continuous", Format( "Best", 12 ) )
					),
					Import Settings(
						End Of Line( CRLF, CR, LF ),
						End Of Field( Comma, CSV( 0 ) ),
						Strip Quotes( 1 ),
						Use Apostrophe as Quotation Mark( 0 ),
						Use Regional Settings( 0 ),
						Scan Whole File( 1 ),
						Treat empty columns as numeric( 0 ),
						CompressNumericColumns( 0 ),
						CompressCharacterColumns( 0 ),
						CompressAllowListCheck( 0 ),
						Labels( 1 ),
						Column Names Start( __namestart__ ), // <<<<<<<<<<<<<<
						Data Starts( __datastart__ ), // <<<<<<<<<<<<<<<<
						Lines To Read( "All" ),
						Year Rule( "20xx" )
					)
				)
			),
		Expr( __namestart__ ), namestart,
		Expr( __datastart__ ), datastart
	)
);
Jim

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: A variable in a loop

Those options go inside the Import Settings.

Open(
  "C:\...\simple.txt",
  columns(
    New Column( "1", Numeric, "Continuous", Format( "Best", 12 ) ),
    New Column( "2", Numeric, "Continuous", Format( "Best", 12 ) )
  ),
  Import Settings(
    End Of Line( CRLF, CR, LF ),
    End Of Field( Comma, CSV( 0 ) ),
    Strip Quotes( 1 ),
    Use Apostrophe as Quotation Mark( 0 ),
    Use Regional Settings( 0 ),
    Scan Whole File( 1 ),
    Treat empty columns as numeric( 0 ),
    CompressNumericColumns( 0 ),
    CompressCharacterColumns( 0 ),
    CompressAllowListCheck( 0 ),
    Labels( 1 ),
    Column Names Start( 1 ), // <<<<<<<<<<<<<<
    Data Starts( 2 ), // <<<<<<<<<<<<<<<<
    Lines To Read( "All" ),
    Year Rule( "20xx" )
  )
)
Craige
AT
AT
Level V

Re: A variable in a loop

Thanks. It is true that column data and name start can be defined in JMP preferences. But I have tried inside open() and it works fine. I just need to parametrize it inside the open(). 

txnelson
Super User

Re: A variable in a loop

I would put the open into Substitution() structure to make the changes and to run the code

datastart = 2;
namestart = 1;

Eval(
	Substitute(
			Expr(
				Open(
					"C:\...\simple.txt",
					columns(
						New Column( "1", Numeric, "Continuous", Format( "Best", 12 ) ),
						New Column( "2", Numeric, "Continuous", Format( "Best", 12 ) )
					),
					Import Settings(
						End Of Line( CRLF, CR, LF ),
						End Of Field( Comma, CSV( 0 ) ),
						Strip Quotes( 1 ),
						Use Apostrophe as Quotation Mark( 0 ),
						Use Regional Settings( 0 ),
						Scan Whole File( 1 ),
						Treat empty columns as numeric( 0 ),
						CompressNumericColumns( 0 ),
						CompressCharacterColumns( 0 ),
						CompressAllowListCheck( 0 ),
						Labels( 1 ),
						Column Names Start( __namestart__ ), // <<<<<<<<<<<<<<
						Data Starts( __datastart__ ), // <<<<<<<<<<<<<<<<
						Lines To Read( "All" ),
						Year Rule( "20xx" )
					)
				)
			),
		Expr( __namestart__ ), namestart,
		Expr( __datastart__ ), datastart
	)
);
Jim
AT
AT
Level V

Re: A variable in a loop

Thanks so much Jim. It works perfectly now.

Craige_Hales
Super User

Re: A variable in a loop

Hm...so it does. This works for me:

n=2; // b
d=4; // d
open(chartoblob(
"a
b
c
d"),columnnamesstart(n),datastarts(d))

I don't think the substitution is required for this. Glad Jim got you going!

Craige