cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
house91
Level I

Munger or Substr?

Hi all,

Working with a dataset where I have four descriptors that I want to utilize in my column headings.

8666_Dataset with Descriptors.jpg

I have not input my numbers yet, but I would like to know if I wanted to change my column headings, in the first four, to a combination of descriptors under "Description" and "Description 2"  for their associated abbreviations what formula I would use besides manually doing it? I'm looking at Substr, but Munger seems to be the one to utilize.

Thank you,

Brandon

1 ACCEPTED SOLUTION

Accepted Solutions
JohnPonte
Staff (Retired)

Re: Munger or Substr?

I think either method would work for you. But in your case, where you know exactly what the strings are and what you want to change them to, I would use Munger, since it is a simple find and replace. I use Substr when I'm trying to find a specific string within a general string, and I don't know what the general string is or if my substring will even exist within it.

If I understand your problem correctly (and I'm not convinced I do) here is the JSL for making the changes as you described:

col = column("Att1_Stat1");

colName = col << getName();

colName = munger(colName, 1, "Att1", :Description[1]);

colName = munger(colName, 1, "Stat1", :Description2[1]);

col << SetName(colName);

col = column("Att1_Stat2");

colName = col << getName();

colName = munger(colName, 1, "Att1", :Description[1]);

colName = munger(colName, 1, "Stat2", :Description2[2]);

col << SetName(colName);

col = column("Att2_Stat1");

colName = col << getName();

colName = munger(colName, 1, "Att2", :Description[2]);

colName = munger(colName, 1, "Stat1", :Description2[1]);

col << SetName(colName);

col = column("Att2_Stat2");

colName = col << getName();

colName = munger(colName, 1, "Att2", :Description[2]);

colName = munger(colName, 1, "Stat2", :Description2[2]);

col << SetName(colName);

Hope this helps!

View solution in original post

5 REPLIES 5
JohnPonte
Staff (Retired)

Re: Munger or Substr?

I think either method would work for you. But in your case, where you know exactly what the strings are and what you want to change them to, I would use Munger, since it is a simple find and replace. I use Substr when I'm trying to find a specific string within a general string, and I don't know what the general string is or if my substring will even exist within it.

If I understand your problem correctly (and I'm not convinced I do) here is the JSL for making the changes as you described:

col = column("Att1_Stat1");

colName = col << getName();

colName = munger(colName, 1, "Att1", :Description[1]);

colName = munger(colName, 1, "Stat1", :Description2[1]);

col << SetName(colName);

col = column("Att1_Stat2");

colName = col << getName();

colName = munger(colName, 1, "Att1", :Description[1]);

colName = munger(colName, 1, "Stat2", :Description2[2]);

col << SetName(colName);

col = column("Att2_Stat1");

colName = col << getName();

colName = munger(colName, 1, "Att2", :Description[2]);

colName = munger(colName, 1, "Stat1", :Description2[1]);

col << SetName(colName);

col = column("Att2_Stat2");

colName = col << getName();

colName = munger(colName, 1, "Att2", :Description[2]);

colName = munger(colName, 1, "Stat2", :Description2[2]);

col << SetName(colName);

Hope this helps!

Craige_Hales
Super User

Re: Munger or Substr?

Good use of munger.  Some ideas: JSL Character String Functions .

Craige
house91
Level I

Re: Munger or Substr?

John this is exactly what I was looking for, thank you.

I've never used the Munger function before, but I wanted to have a formula change the column headings and not just manually input them.

Thank you again.

house91
Level I

Re: Munger or Substr?

So I've run into a new problem.

When the tables are turned into a script and placed in a journal the subsequent table produced from the hyperlink has no data input and the following errors appear:

"could not find column 1 times At rows: {1} Operation: Column, Column/*###*/("Att1_Stat1")"

This error goes from 1-10 in the rows and for each treatment column.

JohnPonte
Staff (Retired)

Re: Munger or Substr?

The script will only work once!  After that, your column headings have been changed. You could wrap each block of code in an if() so it will only attempt to change the column heading if it finds the column with the original name. Or you could remove the script once you've run it or before you save it to a journal.