Subscribe Bookmark RSS Feed

pass column as variable to function for use in distribution

alex

Community Trekker

Joined:

Jun 23, 2011

Hi,
I'm trying to pass the column name to a function and then use it in the Distribution but it comes back with:
A command within the Distribution script was not recognized.
No data to analyze.
it's the Column( varB) line with-in the distribution.
Thanks,
Alex (on Jmp 8)

RuntheGraphs = function ({varB},
show (varB);

Distribution(
Uniform Scaling( 0 ),
Continuous Distribution(
Column( varB),
Horizontal Layout( 1 ),
Vertical( 0 ),
Count Axis( 1 ),
Show Counts( 1 ),
Outlier Box Plot( 0 )
),
Where( :IPRO_TPT_Completed == 1 )
)/*distribution*/
);

c="Cut Sheet";
RuntheGraphs(eval(c));

Message was edited by: alex
5 REPLIES
mattf

Community Trekker

Joined:

Jun 23, 2011

Hi Alex:

Jump into JMP Scripting
By: Wendy Murphrey and Rosemary Lucas

https://support.sas.com/pubscat/bookdetails.jsp?catid=1&pc=61733

Provide an example:

<-

/* Solution 9.2 */

/* Open the Fitness sample data tableNi. */
dt = Open( "$SAMPLE_DATA/Fitness.jmp" );

/* Assign the criteria to a global variable. */
selVar = "M";
yvar = "MaxPulse";
xvar = "RstPulse";
/* Build the main expression. */
bivExpr = Expr(
Bivariate(
Y( :Expr(yvar) ),
X( :Expr(xvar) ),
/* Identify the global variable by wrapping it with the Expr function. */
Where( :sex == Expr( selVar ) )
)
);

/* Resolve the global variable expression first. Then resolve the main expression. */
Eval( Eval Expr( bivExpr ) );

Adapting to you particular example:

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

/* Assign the criteria to a global variable. */
c = "Height";

/* Build the main expression. */
dist = Expr(Distribution(
Continuous Distribution(
/* Identify the global variable by wrapping it with the Expr function. */
Column( :Expr( c ) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Fit Distribution( Normal )
)
)
);

/* Resolve the global variable expression first. Then resolve the main expression. */
Eval( Eval Expr( dist ) );

->

Best regards,
-Matt
alex

Community Trekker

Joined:

Jun 23, 2011

I have the book open right now!
Can you give me the page?
(it looks like you did a put and past but it got lost in the html)
pmroz

Super User

Joined:

Jun 23, 2011

This is a common problem I encounter in JSL. When all else fails I build an expression and then use eval(parse()) on it. Here's some working code:





style="font-size: 10pt; font-family: "Courier New"; color: black;">RuntheGraphs

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">Function

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">
{varB}

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">Show

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">
varB )

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     
dist_expr

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: purple;">"
style="">    
Distribution(





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">           
Uniform
Scaling( 0 ),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">           
Continuous
Distribution(





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Column("

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
style=""> 
varB
style=""> 

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Horizontal
Layout( 1 ),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Vertical(
0 ),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Count
Axis( 1 ),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Show
Counts( 1 ),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">                 
Outlier
Box Plot( 0 )





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">           
),





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">           
Where(
:sex == \!"F\!" )





style="font-size: 10pt; font-family: "Courier New"; color: purple;">
style="">     
)"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">eval

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">parse

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">dist_expr))

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     




style="font-size: 10pt; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">dt

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">open

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"$sample_data\big
class.jmp"

style="font-size: 10pt; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">c

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"height"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">RuntheGraphs(
c )

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 




 

mattf

Community Trekker

Joined:

Jun 23, 2011

Second Try:

alex

Community Trekker

Joined:

Jun 23, 2011

Thanks to both of you. That's great (if not a bit hack-ish.)