cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-870823%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EBucle%20para%20establecer%20una%20f%C3%B3rmula%20de%20normalizaci%C3%B3n%20para%20varias%20columnas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870823%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHola%20comunidad%2C%3C%2FP%3E%0A%3CP%3EEstoy%20intentando%20escribir%20un%20script%20JSL%20para%20establecer%20una%20f%C3%B3rmula%20de%20normalizaci%C3%B3n%20con%20referencia%20de%20columna%20din%C3%A1mica.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EWhat's%20wrong%20here%3F%3CBR%20%2F%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%22Mean(M4_pop)%22%20%26amp%3B%20%22Std%20Dev(M4_pop)%22%20are%20fix%20columns%20that%20are%20to%20be%20used%20for%20the%20normalization.%20%3C%2FCODE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table()%3B%0A%0AnumCols%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Column%20Names(%20Numeric%2C%20%22String%22%20)%3B%0A%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20numCols%20)%2C%20i%2B%2B%2C%0A%0A%20%20%20%20%20colName%20%3D%20numCols%5Bi%5D%3B%20%20%0A%0A%20%20%20%20normColName%20%3D%20colName%20%7C%7C%20%22_norm%22%3B%0A%0A%20%20%20%20dt%20%26lt%3B%26lt%3B%20New%20Column(%0A%0A%20%20%20%20%20%20%20%20normColName%2C%0A%0A%20%20%20%20%20%20%20%20Numeric%2C%0A%0A%20%20%20%20%20%20%20%20Continuous%2C%0A%0A%20%20%20%20%20%20%20%20Formula(%20(colName-%20%3A%22Mean(M4_pop)%22n)%20%2F%20%3A%22Std%20Dev(M4_pop)%22n)%0A%0A%20%20%20%20)%3B%0A%0A%20%20%20%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-870823%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAutomatizaci%C3%B3n%20y%20scripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-870886%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Bucle%20para%20establecer%20una%20f%C3%B3rmula%20de%20normalizaci%C3%B3n%20para%20varias%20columnas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870886%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ETendr%C3%A1s%20que%20evaluar%20colName%20con%20la%20f%C3%B3rmula%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJSL-Cookbook-Archived%2FInsert-one-expression-into-another-using-Eval-Insert-Eval-Expr%2Fm-p%2F48998%23U48998%22%20class%3D%22lia-mention-container-editor-message%20lia-img-icon-tkb-thread%20lia-fa-icon%20lia-fa-tkb%20lia-fa-thread%20lia-fa%22%20target%3D%22_blank%22%3EInsertar%20una%20expresi%C3%B3n%20en%20otra%20usando%20Eval%20Insert%2C%20Eval%20Expr%2C%20Parse%20y%20Substitute%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-870905%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Bucle%20para%20establecer%20una%20f%C3%B3rmula%20de%20normalizaci%C3%B3n%20para%20varias%20columnas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870905%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHola%20David%2C%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EPuede%20que%20haya%20soluciones%20m%C3%A1s%20bonitas%2C%20pero%20esta%20es%20una%20forma%20de%20hacerlo%20funcionar%3A%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table()%3B%0A%0AnumCols%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Column%20Names(%20Numeric%2C%20%22String%22%20)%3B%0A%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20numCols%20)%2C%20i%2B%2B%2C%0A%0A%20%20%20%20colName%20%3D%20numCols%5Bi%5D%3B%0A%20%20%20%20%20%0A%20%20%20%20mean%20%3D%20%22Mean(M4_pop)%22%3B%0A%20%20%20%20%0A%20%20%20%20std%20%3D%20%20%22Std%20Dev(M4_pop)%22%3B%0A%0A%20%20%20%20normColName%20%3D%20colName%20%7C%7C%20%22_norm%22%3B%0A%0A%20%20%20%20dt%20%26lt%3B%26lt%3B%20New%20Column(%0A%0A%20%20%20%20%20%20%20%20normColName%2C%0A%0A%20%20%20%20%20%20%20%20Numeric%2C%0A%0A%20%20%20%20%20%20%20%20Continuous%2C%0A%0A%20%20%20%20%20%20%20%20Formula(%20(as%20column(colName)-%20as%20column%20(mean))%20%2F%20as%20column(Std))%0A%0A%20%20%20%20)%3B%0A%0A%20%20%20%20)%3B%0A%20%20%20%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESalud%2C%3C%2FP%3E%0A%3CP%3EJon%C3%A1s%3C%2FP%3E%3C%2FLINGO-BODY%3E%0A%20%0A%20%0A%20%20%3CLINGO-SUB%20id%3D%22lingo-sub-871629%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Bucle%20para%20establecer%20una%20f%C3%B3rmula%20de%20normalizaci%C3%B3n%20para%20varias%20columnas%3C%2FLINGO-SUB%3E%0A%20%20%3CLINGO-BODY%20id%3D%22lingo-body-871629%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%0A%20%20%20%3CP%3EHola%20Jonas%2C%3C%2FP%3E%20%0A%20%20%20%3CBR%20%2F%3E%20%0A%20%20%20%3CP%3EGracias%20por%20tu%20respuesta.%20Peque%C3%B1os%20cambios%20que%20llevaron%20al%20%C3%A9xito.%3A)%3C%2Fimg%3E%3C%2FP%3E%0A%20%20%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
David_Hanslian
Level II

Loop to set a normalization formula for several columns

Hi community,

I'm trying to write a JSL script to set a normalization formula with dynamic column reference. 

 

What's wrong here?
"Mean(M4_pop)" & "Std Dev(M4_pop)" are fix columns that are to be used for the normalization. 

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

     colName = numCols[i];  

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (colName- :"Mean(M4_pop)"n) / :"Std Dev(M4_pop)"n)

    );

    );

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Loop to set a normalization formula for several columns

Hi David,

 

there might be prettier solutions but this is one way to make it work:

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

    colName = numCols[i];
     
    mean = "Mean(M4_pop)";
    
    std =  "Std Dev(M4_pop)";

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (as column(colName)- as column (mean)) / as column(Std))

    );

    );
    

Cheers,

Jonas

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Loop to set a normalization formula for several columns

You will have to evaluate colName to the formula
Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute 

-Jarmo

Re: Loop to set a normalization formula for several columns

Hi David,

 

there might be prettier solutions but this is one way to make it work:

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

    colName = numCols[i];
     
    mean = "Mean(M4_pop)";
    
    std =  "Std Dev(M4_pop)";

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (as column(colName)- as column (mean)) / as column(Std))

    );

    );
    

Cheers,

Jonas

David_Hanslian
Level II

Re: Loop to set a normalization formula for several columns

Hi Jonas,

 

thanks for your response. Small changes that led to sucess :) 

Recommended Articles