Subscribe Bookmark RSS Feed

Munger or Substr?

house91

Community Trekker

Joined:

Apr 1, 2015

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
Solution

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!

5 REPLIES
Solution

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

Staff

Joined:

Mar 21, 2013

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

Craige
house91

Community Trekker

Joined:

Apr 1, 2015

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

Community Trekker

Joined:

Apr 1, 2015

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

Joined:

Jun 17, 2013

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.