cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
SDF1
Super User

Why does Parse() add extra spaces? And how to get around this?

Hi All,

 

  I'm struggling with how to get around Parse() adding extra spaces because it's interfering with the evaluation of my code.

 

  I have a data table where I have a column of interest that is named something like "AA BBBB CCC(d-d)", and I am doing an evaluation where I want to simulate the estimates of a fit that I've done. The section of code where I'm doing this is the following:

Eval(
	Parse(
		"\[report_of_interest[Number Col Box( 8 )] << Simulate(
			NBSnum,
			Random Seed( RSnum ),
			Out( ]\"
			|| YCols[1] || "\[ ),
			In( :Simulated Y )
			);]\"
	)
);

  This works great for the most part, but the Parse() command adds extra spaces when it parses the variable YCols[1], and when it does that, the Simulate platform thinks that the column doesn't exist because it's looking for a name with extra spaces. When I just evaluate the YCols[1], I get the column name as above: "AA BBBB CCC(d-d)". But, when I Parse(YCols[1]), the actual code that Eval() then runs is using a column with a name that looks like this: "AA BBBB CCC( d - d )", which is not the correct column name because Parse() is putting in extra spaces between the parentheses and the letter "d", as well as extra spaces around the "-" dash character. This is the output in the embedded log when I run just the Parse() part of the code above:

 

report_of_interest[Number Col Box( 8 )] << Simulate(
NBSnum,
Random Seed( RSnum ),
Out( AA BBB CCC( d - d ) ),
In( :Simulated Y )
)

 

  Is there a way to get around this, or another way to build the string for parsing that won't add the extra spaces?

 

  I've even tried the following way to build the string for parsing, but this also leads to the Simulate platform looking for a column name with extra spaces.

str = Eval Insert(
	"report_of_interest[Number Col Box( 8 )] << Simulate(
	NBSnum,
	Random Seed( RSnum ),
	Out("
);
str2 = Eval Insert( "	),
	:Simulated Y )
	)" );
Eval( Parse( str || ":" || Char( Eval( YCols )[1] ) || str2 ) );

  I know JSL doesn't care about the extra white spaces, but JMP does when it comes to column names.

 

  Any thoughts/ideas are much appreciated.

 

Thanks!,

DS

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Why does Parse() add extra spaces? And how to get around this?

Try adding ""n around the column name

Names Default To Here(1);

YCols= {"AA BBBB CCC(d-d)", "b"};

Parse(
	"\[report_of_interest[Number Col Box( 8 )] << Simulate(
		NBSnum,
		Random Seed( RSnum ),
		Out( "]\"
		|| YCols[1] || "\["n ),
		In( :Simulated Y )
		);]\"
);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Why does Parse() add extra spaces? And how to get around this?

Try adding ""n around the column name

Names Default To Here(1);

YCols= {"AA BBBB CCC(d-d)", "b"};

Parse(
	"\[report_of_interest[Number Col Box( 8 )] << Simulate(
		NBSnum,
		Random Seed( RSnum ),
		Out( "]\"
		|| YCols[1] || "\["n ),
		In( :Simulated Y )
		);]\"
);
-Jarmo
SDF1
Super User

Re: Why does Parse() add extra spaces? And how to get around this?

Hi @jthi ,

 

 That did it!

 

Thanks!,

DS

jthi
Super User

Re: Why does Parse() add extra spaces? And how to get around this?

And you should be able to avoid using Parse in this case (if you want to)

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("height+weight", Numeric, Continuous, Formula(
	:height + :weight
));

dist = dt << Distribution(Continuous Distribution(Column(:height)));
ncb = Report(dist)[OutlineBox("Summary Statistics"), Number Col Box(1)];


mycol = "height+weight";
Eval(EvalExpr(
	ncb << Simulate(
		20,
		Random Seed(1),
		Out(:height),
		In(Expr(NameExpr(AsColumn(dt, mycol))))
	)
));

You can see if you run EvalExpr() part, that the column name gets built into "height+weight"n here

ncb << Simulate(20, Random Seed(1), Out(:height), In(:"height+weight"n))
-Jarmo