SPSS side-by-side frequency table - spss

I have a file where each record is about a student. For example:
Student ServiceA ServiceB
Bob ABC ABC
Jane ABC
Jim XYZ
Henry EFG ABC
Laura EFG
Code for the above table:
data list list/student ServiceA ServiceB (3a10).
begin data
"Bob","ABC","ABC"
"Jane","ABC",
"Jim",,"XYZ"
"Henry","EFG","ABC"
"Laura","EFG",
end data.
I want to show a simple table that has the count of services for Service A and B, side by side, like this:
ServiceA ServiceB
[Blank] 2 1
ABC 1 3
EFG 1 1
XYZ 1 0
I've tried Custom Tables and Report Summaries in Rows / Columns, but can't seem to produce this simple table. Any ideas?

This will put the analysis of both variables in the same table:
VARSTOCASES /make Service from ServiceA ServiceB/index src(service)/null=keep.
sort cases by src.
split file by src.
freq service.
split file off.
This still wont put the frequencies side by side, but you can now do that easily using the pivoting trays.

Related

Need help to update record with foreach loop in SSIS

I'm working on data cleansing project where I'm executing 1st stored procedure to get all the data which has issue and store it into a staging table1 with ID, IND_REF, CODE.
Table structure is:
ID | IND_REF|CODE
12 | 2333 |ABC
13 | 1222 |EFG
Now each code associated with IND_ref is primary key of the table2 and email table where data will be updated.
Next I wrote another stored procedure with an IF statement stating,
If code = ABC then update school email as main email where emailtable_ID = staging table IND_REF
Once it update all the row of email table by reference of staging table IND_REF I used another if statement,
IF code = 'EFG' do that.... where table2_ID = staging table IND_REF...
and so on..
Basically I want to update the row of live table by referencing CODE associated with each IND_REF...
Can I achieve this with a SSIS package? Can I loop through the staging table to update the live table? Any help would be much appreciated. I am new to the SQL world so I find it difficult to loop through each record by setting counter to update live table. any help with script would be very helpful.
I don't understand your issue but let me show you an example:
If we have a table like this:
TABLE1
ID ind_ref code
1 1 ABC
2 15 DEF
3 17 GHI
and a table like this:
TABLE2
ind_ref2 code
1 ZZZ
2 XXX
3 DDD
4 ZZZ
5 XXX
15 FFF
17 GGG
Then if we run this query:
UPDATE TABLE2
SET Code = TABLE1.Code
FROM TABLE1
WHERE TABLE1.ind_ref = TABLE2.ind_ref2;
Table 2 will end up like this:
TABLE2
ind_ref2 code
1 ABC <= I got updated
2 XXX
3 DDD
4 ZZZ
5 XXX
15 DEF <= me too
17 GHI <= and me
If this is not your data or your requirement, please take the time to lay out examples as I have: explain the data that you have and what you want it to look like.
Note: SSIS is not required here and neither is looping.

SPSS descriptives long data

I am trying to run descriptives (Means/frequencies) on my data that are in long format/repeated measures. So for example, for 1 participant I have:
Participant Age ID 1 25 ID 1 25 ID 1 25 ID 1 25 ID 2 (Second participant .. etc) 30
So SPSS reads that as an N of 5 and uses that to compute the mean. I want SPSS to ignore repeated cases (Only read ID 1 data as one person, ignore the other 3). How do I do this?
Assuming the ages are always identical for all occurrences of the same ID - what you should do is aggregate (Data => aggregate) your data into a separate dataset, in which you'll take only the first age for each ID. Then you can analyse the age in the new dataset with no repetitions.
you can use this syntax:
DATASET DECLARE OneLinePerID.
AGGREGATE /OUTFILE='OneLinePerID' /BREAK=ID /age=first(age) .
dataset activate OneLinePerID.
means age.

show results from two splunk queries into one

I have two separate splunk queries:
1st Query : Outputs unique user count in last 24 hours
2nd Query : Outputs unique users count in last 24 hours in geo = US
I want to create a timechart that will show , a line chart with % of user everyday from US.
How can this be achieved.
You can join the two queries by using :
|
So your query can look like this:
{firstQuery} as countUS| {secondQuery} as countTotal | eval perc=countUS/countTotal
You can use a conditional to count those from US
Example query:
index=data | timechart dc(user) as dc_user, dc(eval(if(geo=US,user,NULL))) as us_user | eval perc_us=round(us_user/dc_user*100,2) | table _time, perc_us
Alternatively you can use the SPL join command but that would be less efficient as it would have to read the data twice and join the results.
Can you anonymize your data, and show the query here? There's lots of ways to do this in Splunk, but we will need a bit more to go on.
for example
Query: index=myindex sourcetype=mySourcetype | stats count dc(ip) as userTotal | append [ index=myindex sourcetype=mySourcetype region=US | stats dc(ip) as USTotal]

Sorting by rank and total where multiple entries may exist

Ruby 2.1.5
Rails 4.2.1
My model is contributions, with the following fields:
event, contributor, date, amount
The table would have something like this:
earth_day, joe, 2014-04-14, 400
earth_day, joe, 2015-05-19, 400
lung_day, joe, 2015-05-20, 800
earth_day, john, 2015-05-19, 600
lung_day, john, 2014-04-18, 900
lung_day, john, 2015-05-21, 900
I have built an index view that shows all these fields and I implemented code to sort (and reverse order) by clicking on the column titles in the Index view.
What I would to do is have the Index view displayed like this:
Event Contributor Total Rank
Where event is only listed once per contributor and the total is sum of all contributions for this event by the contributor and rank is how this contributor ranks relative to everyone else for this particular event.
I am toying with having a separate table where only a running tally is kept for each event/contributor and a piece of code to compute rank and re-insert it in the table, then use that table to drive views.
Can you think of a better approach?
Keeping a running tally is a fine option. Writes will slow down, but reads will be fast.
Another way is to create a database view, if you are using postgresql, something like:
-- Your table structure and data
create table whatever_table (event text, contributor text, amount int);
insert into whatever_table values ('e1', 'joe', 1);
insert into whatever_table values ('e2', 'joe', 1);
insert into whatever_table values ('e1', 'jim', 0);
insert into whatever_table values ('e1', 'joe', 1);
insert into whatever_table values ('e1', 'bob', 1);
-- Your view
create view event_summary as (
select
event,
contributor,
sum(amount) as total,
rank() over (order by sum(amount) desc) as rank
from whatever_table
group by event, contributor
);
-- Using the view
select * from event_summary order by rank;
event | contributor | total | rank
-------+-------------+-------+------
e1 | joe | 2 | 1
e1 | bob | 1 | 2
e2 | joe | 1 | 2
e1 | jim | 0 | 4
(4 rows)
Then you have an ActiveRecord class like:
class EventSummary < ActiveRecord::Base
self.table_name = :event_summary
end
and you can do stuff like EventSummary.order(rank: :desc) and so on. This won't slow down writes, but reads will be a little slower, depending on how much data you are working with.
Postgresql also has support for materialized views, which could give you the best of both worlds, assuming you can have a little bit of lag between when the data is entered and when the summary table is updated.

Delphi sort by sum of three fields - delphi

I have a database (*.mdb), scheme of connection, that I use in my program:
TADOConnection -> TADOTable
DB has a table named Table1, which is connected by ADOTable. In Table1 there are fields A, B, C - floating point values. I need to sort the table by sums of these numbers.
For example:
Name A B C
------ --- --- ---
John 1 2 5
Nick 1 5 3
Qwert 1 5 2
Yuiop 2 3 1
I need to sort them, so the name, which A+B+C is bigger, would be first.
Sorted variant:
Name A B C
------ --- --- ---
Nick 1 5 3
John 1 2 5
Qwert 1 5 2
Yuiop 2 3 1
How to do this ?
While writing this, I understood what to do: I need a calculated field in the table, which is equal to A+B+C, and I must sort the table using it.
I do not have MS Access but with other Data Base Systems, I would use SQL to achieve this:
There are several SO answers along these lines for MS Access (try Microsoft Access - grand total adding multiple fields together)
So start with something like this:
Select Name, (A+B+C) as total, A, B, C
from table1
order by total desc

Resources