I'm using a Bloomberg terminal to get information about compaines and am strugling with how to set up an array. Here is what I'm attempting to do:

The data will come in like this from theBbloomberg terminal since it is running on a loop for each ticker symbol:

Ticker Symbol GICS Sector
A Health Care
AA Materials
AAPL Information Technology
ABBV Health Care
ABC Health Care
ABT Health Care


As the data comes in, I would like to "basket" each one by sector, like this:
Health Care Materials Information Technology
A AA AAPL
ABBV
ABC
ABT


The problem is, I want to try this (seperately) not only for GICS sectors (which there are 10) but also by sub sector, sub industry, ect. That means there will be both an unknown number of "baskets" and an unknown number of ticker's in each basket. The only thing that will be known is the total number of ticker symbols.

Since I'm not that great at coding here is an example:

Infomation is recieved from Bloomberg => If there is already a "basket" then put the ticker into the basket. If there isn't a "basket" create a new basket and put the ticker into the new basket. Next ticker.