Get name of dimensional array - database

I am currently trying to match a HyperArray parameter to the database.
I am trying to get the match the Dimension name to the database name. I am struggle to call/get the Dimension name. Does anyone have advise on how I could call the dimension name if I select Dimension 1.
Modules is a HyperArray Parameter
Database
Previous Assistance Received

as you know, a variable can have multiple dimensions, and each dimension can have multiple values, where each value is associated to a name.
There are 2 indexes of importance, the first one is the one associated to the index of the dimension, let's call it dimIndex
In your case there's only 1 dimension called Module_List so, dimIndex must be equal to 0
The second one is the value of that dimension, in your case Module_List has values of Busman_113 and Busman_124
Modules.getDimensions()[dimIndex].getIndexName(0) will be equal to "Busman_113"
and
Modules.getDimensions()[dimIndex].getIndexName(1) will be equal to "Busman_124"

Related

How to use a column's value in array index in SAS

I want to subset a dataset based on the value of a column from a set of columns.
For ex,
I want to subset the dataset by age>50 but i have 10 age columns ranging from age1-age10. Also, there is another column named identifier (with values from 1-10) which tells me based on what column should i subset the value.
Let's say my identifier column value is 5, I should check whether the value in column age5 is greater than 50 or not.
This is what I tried, But it's not working.
data library.table2;
set library.table1;
array age[10] age1 -- age10;
if( age(identifier)>50 );
RUN;
The list of variables meant by a positional variables list like age1 -- age10 could be completely different than the variable list meant by a simple enumerated list like age1 - age10. The former looks for all variables BY POSITION between AGE1 and AGE10. It could include 2 variables or 200 variables. It might include some character variables.
If you want AGE1,AGE2,...,AGE10 then you can either list the variables or specify the dimension. If you do not list the actual variable names in some way then it will just append an index number to the name of the array to generate the variable names for the array.
array age age1-age10;
array age[10] ;
If you are a belt and suspenders type of person you can specify both the dimension and the specific variable names.
array age[10] age1-age10;
You might also want to check that IDENTIFIER is a valid index.
if identifier in (1:10) then if not age(identifier)>50 then delete;

Retrieving data from table using cell array - Matlab

I have a table in Matlab crsp and and cell array of numbers that serve as keys. I want to retrieve information from the table using that cell array which is stored as a variable. My code is as follows:
function y = generateWeights(permno_vector, this_datenum, crsp)
crsp(crsp.PERMNO == permno_vector,:);
crsp is defined as a table while permno_vector is the cell array. It contains a couple permnos that are used to retrieve information.
In this case, my code is not working and will not allow me to access the values in crsp. How do we access table values using a vector array?
As James Johnstone points out, the first problem with the code you've posted is that it doesn't assign anything to y, so as written your function doesn't return a value. Once you've fixed that, I assume the error you are seeing is Undefined operator '==' for input arguments of type 'cell'. It's always helpful to include this sort of detail when asking a question.
The syntax
crsp(crsp.PERMNO == x,:)
would return those rows of crsp that had PERMNO equal to x. However if you want to supply a list of possible values, and get back all the rows of your table where your target variable matches one of the values in the list, you need to use ismember:
crsp(ismember(crsp.PERMNO, cell2mat(permno_vector)),:)
if permno_vector is a cell array, or simply:
crsp(ismember(crsp.PERMNO, permno_vector),:)
if you can instead supply permno_vector as a numeric vector (assuming of course the data in crsp.PERMNO is also numeric).

Passing of 2D array into function- why do I need to include column number instead of row number?

In the passing of a 2D array into a function, why do I have to specify the column size (i.e. how many columns does my array have)?
Can it work the other way round- instead of specifying the column size I specify the number of rows?
Consider a table into which you haven't entered any data.
If you do not specify the number of columns, every time you enter new data, it goes into the next column in the first row, and this goes on until all the data is entered. But then all the data is entered in the first row itself, making your table a single row, that's a 1-D array, not a 2-D array.
But if you specify the number of columns, when you hit the limit when entering data, the next piece of data goes to the next set of columns (i.e. the 2nd row) automatically, thus a table is formed.
No, you cannot specify only the number of rows.
Hope I helped!

Returning multiple adjacent cell results from an min array which may include multiple duplicate values

I'm trying to setup a formula that will return the contents of an related cell (my related cell is on another sheet) from the smallest 2 results in an array. This is what I'm using right now.
=INDEX('Sheet1'!$A$40:'Sheet1'!$A$167,MATCH(SMALL(F1:F128,1),F1:F128,0),1)
And
=INDEX('Sheet1'!$A$40:'Sheet1:!$A$167,MATCH(SMALL(F1:F128,2),F1:F128,0),1)
The problem I've run into is twofold.
First, if there are multiple lowest results I get whichever one appears first in the array for both entries.
Second, if the second lowest result is duplicated but the first is not I get whichever one shows up on the list first, but any subsequent duplicates are ignored. I would like to be able to display the names associated with the duplicated scores.
You will have to adjust the k parameter of the SMALL function to raise the k according to duplicates. The COUNTIF function should be sufficient for this. Once all occurrences of the top two scores are retrieved, standard 'lookup multiple values' formulas can be applied. Retrieving successive row positions with the AGGREGATE¹ function and passing those into an INDEX of the names works well.
    
The formulas in H2:I2 are,
=IF(SMALL(F$40:F$167, ROW(1:1))<=SMALL(F$40:F$167, 1+COUNTIF(F$40:F$167, MIN(F$40:F$167))), SMALL(F$40:F$167, ROW(1:1)), "") '◄ H2
=IF(LEN(H40), INDEX(A$40:A$167, AGGREGATE(15, 6, ROW($1:$128)/(F$40:F$167=H40), COUNTIF(H$40:H40, H40))), "") '◄ I2
Fill down as necessary. The scores are designed to terminate after the last second place so it would be a good idea to fill down several rows more than is immediately necessary for future duplicates.
¹ The AGGREGATE function was introduced with Excel 2010². It is not available in earlier versions.
² Related article for pre-xl2010 functions - see Multiple Ranked Returns from INDEX().
The following formula will do what I think you want:
=IF(OR(ROW(1:1)=1,COUNTIF($E$1:$E1,INDEX(Sheet1!$A$40:$A$167,MATCH(SMALL($F$1:$F$128,ROW(1:1)),$F$1:$F$128,0)))>0,ROW(1:1)=2),INDEX(Sheet1!$A$40:$A$167,MATCH(1,INDEX(($F$1:$F$128=SMALL($F$1:$F$128,ROW(1:1)))*(COUNTIF($E$1:$E1,Sheet1!$A$40:$A$167)=0),),0)),"")
NOTE:
This is an array formula and must be confirmed with Ctrl-Shift-Enter.
There are two references $E$1:$E1. This formula assumes that it will be entered in E2 and copied down. If it is going in a different column Change these two references. It must go in the second row or it will through a circular reference.
What it will do
If there is a tie for first place it will only list those teams that are tied for first.
If there is only one first place but multiple tied for second places it will list all those in second.
So make sure you copy the formula down far enough to cover all possible ties. It will put "" in any that do not fill, so err on the high side.
To get the Scores use this simple formula, I put mine in Column F:
=IF(E2<>"",SMALL($F$1:$F$128,ROW(1:1)),"")
Again change the E reference to the column you use for the output.
I did a small test:

Excel arrays count totals using criterias from multiple ranges (or sheets)

What I would like to do is to count the amount of lines that matches criterias to be verified in two arrays.
I can't use VBA, add new columns (for instance a new column with VLOOKUP formula) and preferably use arrays.
I have two separate ranges, each with a ID column for the identifier and other fields with data.
For instance, range 1:
Range 2:
If I had only to check the first range I would do:
={SUM((D4:D7="Red") * (E4:E7="Big"))}
But I don't know how to check also using data from the other range.
How, for example, to count the number of items that are Red, Big and Round by using both Ranges ?
Put this in the cell F4:
=IF((VLOOKUP(C4,$C$11:$D$12,2)="Round")*(D4="Red")*(E4="Big"),1,"")
Note that the behavior of VLOOKUP is that it finds the value up to the first parameter. Since there's no 1 in your second dataset, this first cell is going to show "#N/A", which I don't know how to solve, but when you extend this formula down to also compare the other sample data in the first set, the ID numbers 2 and 4 will show up as "yes" for you.
Edit: You wanted a count of this list. So after this, it should be easy to get a count of cells in this column using the COUNT function.
Try this array formula
=SUM((D4:D7="Red")*(E4:E7="Big")*ISNUMBER(MATCH(C4:C7,IF(D12:D13="Round",C12:C13),0)))
The last part is the added criterion you want - the IF function returns {2,4} [IDs where Data 3 is "Round"] and then you can use MATCH to compare C4:C7 against that. If there is a match you get a NUMBER (instead of #N/A) so you can then use ISNUMBER to get TRUE/FALSE and that feeds in to your original formula - result should be 2

Resources