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%3ESchleife%20zum%20Festlegen%20einer%20Normalisierungsformel%20f%C3%BCr%20mehrere%20Spalten%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870823%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHallo%20Community%2C%3C%2FP%3E%0A%3CP%3EIch%20versuche%2C%20ein%20JSL-Skript%20zu%20schreiben%2C%20um%20eine%20Normalisierungsformel%20mit%20dynamischer%20Spaltenreferenz%20festzulegen.%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%3EAutomatisierung%20und%20Skripting%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%3EBetreff%3A%20Schleife%20zum%20Festlegen%20einer%20Normalisierungsformel%20f%C3%BCr%20mehrere%20Spalten%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870886%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ESie%20m%C3%BCssen%20colName%20zur%20Formel%20auswerten%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%3EF%C3%BCgen%20Sie%20einen%20Ausdruck%20in%20einen%20anderen%20ein%2C%20indem%20Sie%20Eval%20Insert%2C%20Eval%20Expr%2C%20Parse%20und%20Substitute%20verwenden.%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%3EBetreff%3A%20Schleife%20zum%20Festlegen%20einer%20Normalisierungsformel%20f%C3%BCr%20mehrere%20Spalten%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870905%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHallo%20David%2C%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EEs%20gibt%20vielleicht%20sch%C3%B6nere%20L%C3%B6sungen%2C%20aber%20so%20kann%20es%20funktionieren%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%3EProst%2C%3C%2FP%3E%0A%3CP%3EJonas%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%3EBetreff%3A%20Schleife%20zum%20Festlegen%20einer%20Normalisierungsformel%20f%C3%BCr%20mehrere%20Spalten%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%3EHallo%20Jonas%2C%3C%2FP%3E%20%0A%20%20%20%3CBR%20%2F%3E%20%0A%20%20%20%3CP%3EDanke%20f%C3%BCr%20deine%20Antwort.%20Kleine%20%C3%84nderungen%2C%20die%20zum%20Erfolg%20f%C3%BChrten%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