cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
mquyen
Level I

Concat the list that have variable that changed in a loop

Hi, 
I'm struggle to concat multiple list that has variable in it. I have a list, each item is string that is concatenated from a user-input variable. Since the variable is changed per loop, how I can get the list updated, and concat that list to other lists.

bank_pcs = {"BGB1BESS001_B"||bank||"_W","BGB1BESS001_B"||bank||"_A","BGB1BESS001_V"||bank||"_W"};
For (i = 1, i<=6, i++,
		bank_num = 6*(k-1)+i;
		bank = char(bank_num,10,0);
		Eval list (bank_pcs);
		bank_tags_i = bank_pcs;	
		bank_tags = concat (bank_tags, bank_tags_i)
)

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User (Alumni)

Re: Concat the list that have variable that changed in a loop

You were almost there.  You had the evallist(bank_pcs) but that's not what you're assigning to bank_tags_i.  This works for me.  

 

NamesDefaultToHere(1);
bank_pcs = {"BGB1BESS001_B"||bank||"_W","BGB1BESS001_B"||bank||"_A","BGB1BESS001_V"||bank||"_W"};
For (i = 1, i<=6, i++,
    bank_num = i; // changing this from yours because I assume you also have a k loop
    bank = char(bank_num,10,0);
    bank_tags_i = Evallist(bank_pcs);	
    if(i==1, 
        bank_tags = bank_tags_i // just if it isn't started yet. you're probably doing this in your k loop
    , //else
        bank_tags = concat (bank_tags, bank_tags_i)
    )
);
bank_tags;
Vince Faller - Predictum

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Concat the list that have variable that changed in a loop

See if this will give you what you want

For( i = 1, i <= 6, i++,
	bank_num = 6 * (k - 1) + i;
	theBankValue = Char( bank_num, 10, 0 );
	Eval(
		Substitute(
				Expr(
					bank_pcs = {"BGB1BESS001_B" || bank || "_W", "BGB1BESS001_B" || bank || "_A", "BGB1BESS001_V" || bank ||
					"_W"}
				),
			Expr( bank ), theBankValue
		)
	);
	bank_tags_i = bank_pcs;
	bank_tags = Concat( bank_tags, bank_tags_i );
);
Jim
vince_faller
Super User (Alumni)

Re: Concat the list that have variable that changed in a loop

You were almost there.  You had the evallist(bank_pcs) but that's not what you're assigning to bank_tags_i.  This works for me.  

 

NamesDefaultToHere(1);
bank_pcs = {"BGB1BESS001_B"||bank||"_W","BGB1BESS001_B"||bank||"_A","BGB1BESS001_V"||bank||"_W"};
For (i = 1, i<=6, i++,
    bank_num = i; // changing this from yours because I assume you also have a k loop
    bank = char(bank_num,10,0);
    bank_tags_i = Evallist(bank_pcs);	
    if(i==1, 
        bank_tags = bank_tags_i // just if it isn't started yet. you're probably doing this in your k loop
    , //else
        bank_tags = concat (bank_tags, bank_tags_i)
    )
);
bank_tags;
Vince Faller - Predictum
Craige_Hales
Super User

Re: Concat the list that have variable that changed in a loop

or, if you want a list-of-lists:

k = 11;
bank_tags = {};
bank_pcs = {"BGB1BESS001_B" || bank || "_W", "BGB1BESS001_B" || bank || "_A", "BGB1BESS001_V" || bank || "_W"};
For( i = 1, i <= 6, i++,
	bank_num = 6 * (k - 1) + i;
	bank = Char( bank_num, 10, 0 );
	bank_tags_i = Eval List( bank_pcs );
	bank_tags[1 + N Items( bank_tags )] = bank_tags_i;
);
Show( bank_tags );
/*{{"BGB1BESS001_B61_W", "BGB1BESS001_B61_A", "BGB1BESS001_V61_W"}, 
{"BGB1BESS001_B62_W", "BGB1BESS001_B62_A", "BGB1BESS001_V62_W"}, 
{"BGB1BESS001_B63_W", "BGB1BESS001_B63_A", "BGB1BESS001_V63_W"}, 
{"BGB1BESS001_B64_W", "BGB1BESS001_B64_A", "BGB1BESS001_V64_W"}, 
{"BGB1BESS001_B65_W", "BGB1BESS001_B65_A", "BGB1BESS001_V65_W"}, 
{"BGB1BESS001_B66_W", "BGB1BESS001_B66_A", "BGB1BESS001_V66_W"}}*/

If you want a string rather than a list, try @vince_faller  answer with Concat Items( bank_tags, "," ) to get the list items in a string with commas.

Craige
mquyen
Level I

Re: Concat the list that have variable that changed in a loop

Thank you! It works just as I expected. 

Recommended Articles