As the title says.
What I'm trying to do is a way to set the labels of a column equal to the value in another column.
A B
1 Car
2 Bike
3 Van
1 Car
3 Van
Column A contains the numeric values. Column B contains the labels.
I want to tell SPSS to take the value 1, and assign it the label "Car" (and so on) as clasically is done manually with:
VALUE LABELS
1 "Car"
2 "Bike"
3 "Van".
Execute.
The syntax below will automatically create a new syntax that adds the value labels as you described.
Before starting, I'm recreating the sample data you posted to demonstrate on:
data list list/A (f1) B (a10).
begin data
1 "Car"
2 "Bike"
3 "Van"
1 " Car"
3 "Van"
end data.
dataset name orig.
Now we get to work:
* first we aggregate the data to get only one line for every value/label pair.
dataset declare agg.
aggregate out=agg /break A B /nn=n.
dataset activate agg.
* now we use the data to create a syntax file with the value label commands.
string cat (a50).
compute cat=concat('"', B, '"').
write out="yourpath\my labels syntax.sps" /"add value labels A ", A, cat, ".".
execute.
* getting back to the original data we can now execute the syntax.
dataset activate orig.
insert file="yourpath\my labels syntax.sps".
Related
I'm trying to write a formula that gives a running count of Issues for a given day. In other words: the output should enumerate each Issue for a given date (returning blank if Issue is blank), and then start again at 1 for the first issue in a subsequent date.
I've hard-coded the expected outputs in the "desired output" column (column I):
Sample dataset is in this sheet. Key pieces:
Column B contains the date
Column E contains the T-shirt size severity of each Issue
Column F contains a numerical translation of column E
Column G contains a binary output of whether there was an Issue
In my attempt (column J), I've gotten close using
=ArrayFormula(MMULT((ROW($B3:$B)>=TRANSPOSE(ROW($B3:$B))) * EXACT($B3:$B,TRANSPOSE($B3:$B))^1, ($G3:$G)^1))
...but it's not quite what I want, as:
this repeats values instead of giving blanks (e.g. row 8, 11)
this gives 0s instead of giving blanks (e.g. row 3, 4)
See Validation (column L).
Any ideas on how to get to what I'm looking for?
Just wrap your formula in the IF function
=ArrayFormula(IF(F3:F="",,YOUR.....FORMULA))
In other words
=ArrayFormula(IF(F3:F="",,
MMULT((ROW($B3:$B)>=TRANSPOSE(ROW($B3:$B))) * EXACT($B3:$B,TRANSPOSE($B3:$B))^1, ($G3:$G)^1)
))
Data:
Row A
House;Farm;Zoo
House;Farm
House, Zoo
Row B
Dog;Cat;Lamb;Tiger
Dog;Bunny;Chicken,Fish
Lizard;Cat;Cow
Table 1
House
Dog
Cat
Mouse
Fish
Chicken
Table 2
Zoo
Tiger
Bear
Seal
Table 3
Farm
Bunny
Duck
Lamb
Cow
Horse
Question In Google Sheets
Ok I am trying to figure out how to calc the Column A based on what string is in the Column B The definition of what is in the B Column comes form the three tables in the bottom. Any help would be wonderful!
So here is one way. In some other region of the table, from which you will copy column A at the end, set up the following expression for each row, starting in column B. I am imagining your =original list with column A to be calculated starts in row 1 (so B1 is dog, C1 is cat, and so on).
Suppose your 3 tables sit in rows 6 to 8.
Some rows below, in column A, paste the following:
=IF(ISBLANK(B1),"",IFERROR(QUERY($A$6:$F$8,"Select A where "&"(B = '"&B1&"') OR " & "(C= '"&B1&"') OR "& "(D= '"&B1&"') OR "& "(E= '"&B1&"') OR (F='"&B1&"')")))
Let me unpack that. If the entry is blank, we will leave the corresponding item empty. Similarly, if our query fails, leave it blank. But the query says look in the tables, find the match, and give us the corresponding column A value.
Drag this formula right 3 more columns for a total of 4, which is the longest length of animal list we're trying to cover. You end up with the corresponding places (if any), cell by cell. Also drag this formula down 2 more columns so you get each row.
Clinch by doing the following one column further over. I was in row 10, your row may vary.:
=textjoin(";",true,transpose(unique(transpose(A10:D10))))
this puts togethjer a list of the unique, noempty, values, separated by semicolons.
Drag this down 2 columns, and then go back let you A1=the top corresponding entry, drag down, and you're set.
EDIT: The above assumes Dog, Cat, Lamb, and Tiger are spread across cells in columns B, C, D, and E. If not and they are in just one cell, you may need something like in the C column =split(B1,";") and to adjust columns in my formulas over by 1.
I'm working with the following table:
I need a formula I can use on a different sheet that counts how many classes were cancelled for each of the groups like:
GE COL INT MIX W 2
GE COL INT 1 W 0
The criteria to decide if a class was cancelled or not is to type "C" in one of the columns for the class (i.e. January 2, meaning second class in January). In the example table you can see that the 4 people are part of 2 groups, 2 per group; if I write C for 2 of them in the same group I want the macro to only count 1 cancelled class instead of counting both "C"s.
All of the space where the "C"s will be written (Month columns) is a named range = "Attendance" and there's also a named range for the names of all groups = "Groups".
I'm using the following simple formula:
=COUNTIFS(METRICS!F:F,H5,Attendance,"C")
METRICS!F:F Refers to the sheet where the table I just showed you is and F is the column where the levels are. H5 is the cell in the other sheet where I'm comparing the group name to make sure it's the same. Attendance is the range where I'll be writing "C".
However, I get the error:
Array arguments to COUNTIFS are of different size.
And that would count all "C"s, not only the ones I need.
A simple solution would be to add a column after the group name that counts absences, and then use UNIQUE() over the group names and absence count to get a unique list. eg.
Alternately, to do this without the extra column, first create a unique list of group names with =UNIQUE(Groups).
Then add a named range called GroupAttendance that includes the ranges of both Groups and Attendance.
Lastly, fill the column next to the group names with:
=COUNTIF(FILTER(UNIQUE(GroupAttendance), UNIQUE(Groups) = A2), "C")
eg.
I have the following Google Sheets data:
Name1 Name2 Name3 Value
A B C 20
B A C 30
C D F 40
What I'm trying to do is see if a specific name appears in any of the three name columns. If it does, then sum all the values in the "Value" column for all matching rows.
For example, I want to sum all of the values for name "A". That name only appears on the first two rows, so it should do 20+30 to give me 50. If I change the searched name to "C", that appears in all three rows so it should sum all of the numbers: 20+30+40. The algorithm needs to adjust and search appropriately.
=DSum will work
With the example you give use
=dsum(A1:D4,D1,{A1;"A"})+dsum(A1:D4,D1,{B1;"A"})+dsum(A1:D4,D1,{C1;"A"})
You can swap the "A" for a Cell reference
see https://drive.google.com/previewtemplate?id=0As3tAuweYU9QdEVHdTFHNzloSTY4LVYxdW9LdHRHbEE&mode=public#
I am trying to generate a random Cell from specific range:
I need to each cell Row to generate a random selection from a a specific column (range)
below is a picture of my set up and my failed attempts:
You can do this like this:
Add a random number next to your data set using =RAND(). I've used column B, but you can put it wherever you like.
Add this formula to cells C2 to H2
=INDEX($A$2:$A$21,RANK.EQ(INDEX($B$2:$B$21,COLUMN()-2),$B$2:$B$21))
How it works:
RAND() returns a random number in the range [0..1) This is used as a random sort order for your data
Breaking down the formula:
COLUMN()-2 returns a sequential number 1..6 for columns C to H
INDEX($B$2:$B$21, ... ) returns the 1st to 6th number from the random number list
RANK.EQ( ... ,$B$2:$B$21) returns the position of the random number in the sorted random number list, 1..20.
=INDEX($A$2:$A$21, ... ) returns an item from your data set, based on the random rank from above.
Note: This will return a new randon sample each time Excel recalculates.
The only way to make a random selection that does not repeat is to make an array of integers, than randomize it, and than take out one by one.
For example you start with:
1 2 3 4 5 6 7
you randomize it (swap elements randomly)
2 4 5 1 7 3 6
than you take elements out one by one. (keep an index of how much elements you used in some cell)
Ok here is one trick, add another column with random numbers, than select both random column and range column and click the sort button (picture is from libreoffice but there is a similar button in excel) This will randomize your range column. Than you simply assign values to "w-1" : "w-6" like this =B2, =B3, =B4, =B5, =B6, =B7
I tried this and it works like you wanted, the only problem is it will shuffle values in your range column.