Selecting cases based on values in previous rows - spss

I have a binominal value in SPSS called "emotion" that contains "91" and "95". I would like to select all cases that come after twice "95" and are encoded with "91" themselves. Does anybody know a synthax that makes this possible?

Make sure your data is sorted in the relevant order, then run this:
compute selectthis=(yourvar=91 and lag(yourvar)=95 and lag(yourvar,2)=95).
exe.
select if selectthis=1.

Related

Removing observations from SPSS Dataset

I would like to delete some observations from the table in my SPSS, if values meet, for instance:
If product + value from column meet, I want to remove it/make it SYSMIS (only this observation, the observation from another column for this row needs to be still available, so make flag and temporary select is not enough)
Tried several approaches like:
RECODE VAR2(If(PRODUCT=1 AND VAR2=2000) = SYSMIS)(ELSE=COPY)
EXECUTE.
IF(PRODUCT=1 AND VAR2=2000) RECODE VAR2(SYSMIS)(ELSE=COPY)
EXECUTE.
None of it works
Is there a way to remove observations in another way than delete it from raw data? I'd like to avoid it
You might save a lot of work by looking up some basic spss syntax tutorials. See here for a good site.
In the present case all you need is this:
If PRODUCT=1 AND VAR2=2000 VAR2=$SYSMIS.
To make your syntax work with recode, you can do this:
DO IF (PRODUCT=1 AND VAR2=2000).
RECODE VAR2 (ELSE=SYSMIS).
END IF.
It sounds like you might not want to delete the original data, but instead just run your analyses on a subset of data. In that case, use SELECT IF:
SELECT IF (PRODUCT=1 AND VAR2=2000).
Or:
SELECT IF NOT (PRODUCT=1 AND VAR2=2000).
This will delete any row that doesn't fit the condition, and so all subsequent analysis will include only the rows that do.
If you want to be able to filter the rows only temporarily - you can use filter command instead of select.

Google Spreadsheet Re order Columns

I'll explain an example of the situation before I ask the question.
If I have a pile of 5 numbered boxes and I scan them into a spreadsheet in the following order. 4,2,3,5,1
I copy that list into another program which adds more info to each number (which is what I want) but messes up the order. So now it is 3A,4D,1C,2B,5E.
Is there a formula I can use to reorder my new list to the original? I want to keep the original order as I print labels for these boxes and this would keep the order, meaning ordering both numerically won't work.
Thanks,
Graeme
I'd recommend an HLookup. Look for the character in your original list and add "*" which is a wild card for the second character.
Assumptions:
The first character is unique in the set.
Each value is in its own cell.
The original list is retained after intermediate program runs.

How to Find out if a column contains any duplicates

I have a column of numbers. I want to know if there are any duplicates. I don't need to know how many or what their value is. I just want to know if there are any.
The best way I could figure out was to have another column of equal height to the column of numbers, with the formula:
=countif(A:A,A1)>1
So this will put a TRUE next to every number that has one or more duplicates in the list.
From here I need to see if this second column contains a TRUE.
So I have a final cell with this formula in it:
=lookup(true, B:B)
This always displays FALSE, even when there are duplicates in the list, with corresponding "TRUE" values next to them in column B.
Also, is there a simpler way of solving this problem?
Note: I can get it to work if the single cell result simply does an =OR(B:B) but I still want to know why my first way won't work and if there is an all around simpler way of doing this.
you can use both =unique(A:A) and also =counta(unique(A:A))
note: the A:A is just a dummy array i threw in for example, replace with whatever column you want to refer to.
to get a final yes or no, you could nest it together by putting =if(eq(counta(A:A),counta(unique(A:A))),"No Duplicates", "Contains Duplicates")
I'm not sure whether simpler (I am confident the formula could be simplified!) but copy/pasting the following might be deemed so:
=sum(if(ARRAYFORMULA(countif(A:A,A1:A)>1),1,0))
This should return 0 only if there are no duplicates. If a single entry is repeated twice (three instances) and all other values are unique, the result should be 3.
TRUE is curious as the behaviour is not what I expected and I differs from Excel where true would be converted to TRUE, which normally indicates an automatic change from text to function. I don't have an explanation but it may be connected with lookup because the boolean behaves as I would expect in say an if formula.

Automatically updating Data Validation lists based on user input

I have a very large data set (about 16k rows). I have 10 higher level blocks and within each block I have 4 categories (10 rows for each) which use Data Validation lists to show items available in each category. The lists should automatically update based on user input. What I need your help with is that I want to use the same data set for each block and preferably a least calculation/size intensive approach. I have put together a sample file that outlines the issue with examples.
Sample File
Thank you for your help in advance.
Okay, I've found something, but it can be quite time consuming to do.
Select each range of cells. For instance, for the first one, select B3:B18 and right click on the selection. Find 'Name a Range..." and give it the name "_FIN_CNY". Repeat for all the other ranges, changing the name where necessary.
Select the first range of cells to get the data validation, and click on "Data validation", pick the option "Allow: List" (you already have it) and then in the source, put the formula:
=INDIRECT($G$4&"_CNY")
$G$4 is where the user will input. This changes as you change blocks.
_CNY is the category. Change it to _CNY2 for the second category.
Click "OK" and this should be it. Repeat for the other categories.
I have put an updated file on dropbox where you can see I already did it for the data of _FIN for categories CNY, CNY2 and INT and did the one for _GER as well. You'll notice the category of INT for _GER doesn't work, that's because the Named Range _GER_INT doesn't exist yet.

How do I use Macros to copy select data from one worksheet to another on Excel?

I need to create a Macro on Excel to keep track of changing contracts. There's already an existing macro that updates the contract data so I need to create another macro...
There are two worksheets. On the first worksheet is a bunch of data with each row representing one contract. There are several categories (Contract #, Date, Price, etc.).
I need to write a Macro that finds only certain contracts fitting specific criteria (like, contacts at a specific date or a certain price), copies and pastes them into the second worksheet.
What I've done so far:
I've figured out a bit of a convoluted way of doing it using IF and OR functions. So using OR I specify the criteria and IF to basically find the corresponding data if things are TRUE.
When things are false, a 0 is entered. The problem is I have tons of rows of zeroes---rows/contracts that didn't fit the criteria. When I try to use the find command (CTRL+F) to find, highlight, and properly delete (with rows shifted up) all the zeroes, Macro doesn't record it and I'm not sure how to write it in the code.
Any insight would help!
Just change your formula to:
=IF(OR(TermSheet!$E40=41220,TermSheet!$M40="bpxx"),TermSheet!E40,"")

Resources