Tuesday 23 June 2009

SPLIT FILE tip

It is really easy to split file in SPSS, and we all know that.. I don't think I need to write why it is important to use this command... But when splitting, please make sure that you SORT the file with the SPLIT variable. So for example if you are sorting your data file on gender, first sort the file on gender, then turn split on, either using syntax or menu (it does not matter)!!!

Wednesday 17 June 2009

Alter type (change variable type)

alters the type of the variable and also changes the length. For example, to change numeric to string or vice versa. You can use this command for single, multiple or ALL variables in your file. Here is the command for all variables.

ALTER TYPE ALL (A=A200).

the above will convert all the numeric to string with 200 character length. But it does not allow you to create a new version of the variable (unlike RECODE OR AUTORECODE).

For a good description of converting variable type see this UCLA page:
http://www.ats.ucla.edu/stat/spss/faq/stringnum.htm

Another good page to look at this is at the following user comment in a google group:
http://groups.google.com/group/comp.soft-sys.stat.spss/browse_thread/thread/0560f3240bb41edc?pli=1

Thursday 4 June 2009

The AMAZING TABLES of SPSS

Here are some examples in SYNTAX:

****don't forget to create a variable called t which is equal to 1*********.

COMPUTE t=1.


TABLE
/ftot t 'Total'
/tab (q405a +q405b +q405c +q405d +q405e +q405f +q405g +q405h +q405i
+q405j +q405k +q405l) by place +t
/title "danger signs pregnancy"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q406a +q406b +q406c +q406d +q406e +q406f +q406g) by place +t
/title "dduring delivery"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q407a +q407b +q407c +q407d +q407e +q407f +q407g ) by place +t
/title "during post partum period"
/sta cpct ('%' (f5.1): place) count.


TABLE
/ftot t 'Total'
/tab (q408a +q408b +q408c +q408d +q408e +q408f +q408g +q408h +q408i
+q408j +q408k +q408l) by place +t
/title "danger signs immediately after birth of child (1 hour)"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q409a +q409b +q409c +q409d +q409e +q409f +q409g +q409h +q409i
+q409j +q409k +q409l + q409m + q409n)by place +t
/title "danger signs immediately after birth of child (7 days)"
/sta cpct ('%' (f5.1): place) count.


TAB
/ftot t 'total'
/mrgroup anc2 q805a q805b q805c
/tab anc2 + t by district + district>place + t
/sta cpct((f5.1):district place).

System Variables

Following are the three main System Variables:

$jdate

This variable gives the current date as the number of days from October 14, 1582.

Example:
COMPUTE today = $jdate.
exe.

$sysmis
This can be used when you want to specify that a newly created variable (or some of its values) should be set to system missing.

Example:
compute miss = $sysmis.
compute miss1 = 1.
if missing(q1) or missing(q3) miss1 = $sysmis.

$casenum
You can use this variable if you want to create an id variable that is part of your data set.

Example:
compute id = $casenum.
exe.

Source: http://www.ats.ucla.edu/stat/spss/seminars/spss_syntax/default.htm

Rename Variables

Here is the syntax:

RENAME VARIABLES {(OLD varname= NEW varname) [(varname ...)]}
{(varnames=varnames) }

Example:
RENAME VARIABLES (tm6 = Field2)(tm5 = Field1)(tm3 = MS)(tm4 = Language)(tm10
= Code)(tm1 = Query)(tm11 = Query_Code)(tm9 = Referred_to)(tm2 =
Remarks)(tm7 = Source)(tm8 = Occupation)(tm12 = Card) .


Variables can also be renamed from the Variable View tab.

Delete existing Variables

To delete one or multiple variable(s) from your data file, through syntax, use the following command:

DELETE VARIABLES varlist.

This command takes effect immediately. It does not read the active dataset or execute pending transformations. See Command Order for more information.
Example

DElETE VARIABLES varX varY thisVar TO thatVar.

Real Example:

DELETE VARIABLES Field2 Field1 MS Language Code Query Query_Code Referred_to
Remarks Source Occupation.

RENAME VARIABLES (tm6 = Field2)(tm5 = Field1)(tm3 = MS)(tm4 = Language)(tm10
= Code)(tm1 = Query)(tm11 = Query_Code)(tm9 = Referred_to)(tm2 =
Remarks)(tm7 = Source)(tm8 = Occupation)(tm12 = Card).