LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 15 Sep 2005 14:08:24 +0200
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Georg Maubach <>
Subject:      Macro to create tables of a range of variables
Content-Type: text/plain; charset="us-ascii"

Hi all,

as some of you know I am a using macros a lot. Some list members helped me a lot when creating new macros for the projects I have to carry out for my company.

This time I acted on a suggestion of Raynald Levesque described in his book "SPSS Programming and Data Management" which I recommend to all list members.

The macro I wrote creates CTABLES from a list of variables handed over to the macro as a parameter. The clue is that you can even hand over variables using the "TO" statement. It can be of great help if you need to get an overview over the data set for a given set of variables.

The macro is well documented. Should any question arise please feel free to ask using the list. I will respond as soon as possible.

And here comes the macro:

---- schnipp -----

/* [ Name ] ----------------------------------------------*/. /* @basetab (BASE TABle for basic descriptive analysis) /* /* [ Status ] --------------------------------------------*/. /* Author : Raynald Levesque, Georg Maubach (MRSC) /* Date : 15-Sep-2005 /* Status : released /* Version : 5 /* Release : 1 /* /* [ Description ] ---------------------------------------*/. /* This macro creates the table for a basic descriptive /* analysis. The number of responses and the column per- /* centages are shown. /* /* [ Parameter ] -----------------------------------------*/. /* rowvars (unquoted) = Variables that define the rows /* of the table. These variables will /* be analysed. /* colvars (unquoted) = Variables that define the columns /* of the table. These variables /* define the data cuts. /* title (quoted) = The title for the table. /* /* [ Result ] --------------------------------------------*/. /* The macro creates a table or a cross table using CTABLES. /* The macro can be called with one or more row variables /* and with one or more column variables. /* The row variables and the column variables can be given /* with the "TO" statement. All variables within this range /* referring to the order in the data dictionary will be /* used to create the table. /* One row variable has at least to be handed over to the /* the macro. The column variables can be omitted completely. /* The title can be omitted either. /* /* [ Operation ] -----------------------------------------*/. /* The macro determines if the word " TO " is in the para- /* meters. If it is the " TO " is cut out and the head and /* the tail of the variable lists is generated. If is not /* the head and the tail of the variable list are generated /* directly. /* /* [ Example ] -------------------------------------------*/. /* Examples for calling the macro: /* @basetab rowvars=q1. /* @basetab rowvars=q1 /colvars=q17. /* @basetab rowvars=q1 q2. /* @basetab rowvars=q1 q2 /colvars=q17. /* @basetab rowvars=q1 q2 /colvars=q17 /title="Table 10". /* /* [ Release Notes ] -------------------------------------*/. /* None. /*--------1---------2---------3---------4---------5-------*/.

DEFINE @basetab (rowvars = !CHAREND('/') /colvars = !CHAREND('/') /title = !CMDEND)

/* Keep only variables to be sorted */ !IF (!INDEX(!UPCASE(!rowvars),' TO ') > 0) !THEN !LET !hrows = !HEAD(!rowvars) !LET !trows = !TAIL(!rowvars) !LET !trows = !TAIL(!trows) !IFEND

!IF (!INDEX(!UPCASE(!colvars),' TO ') > 0) !THEN !LET !hcols = !HEAD(!colvars) !LET !tcols = !TAIL(!colvars) !LET !tcols = !TAIL(!tcols) !IFEND

/* Determine first and last variable in variable lists */ !IF (!INDEX(!UPCASE(!rowvars),' TO ') <= 0) !THEN !LET !hrows=!HEAD(!rowvars) !LET !trows=!TAIL(!rowvars) !IFEND

!IF (!INDEX(!UPCASE(!colvars),' TO ') <= 0) !THEN !LET !hcols=!HEAD(!colvars) !LET !tcols=!TAIL(!colvars) !IFEND

/* Create table */ CTABLES /TABLE !CONCAT(!hrows," [C]") !IF (!hrows <> !trows) !THEN !DO !element !IN (!trows) !CONCAT(" + ",!element," [C]") !DOEND !IFEND !IF (!colvars = !NULL) !THEN [COUNT 'n' F40.0, COLPCT.COUNT '%' PCT40.1] !IFEND !IF (!colvars <> !NULL) !THEN BY !CONCAT(!hcols," [C]") [COUNT 'n' F40.0, COLPCT.COUNT '%' PCT40.1] !IF (!hcols <> !tcols) !THEN !DO !element !IN (!tcols) !CONCAT(" + ",!element," [C]") !DOEND !IFEND !IFEND /CATEGORIES VARIABLES=!CONCAT(!rowvars," ",!colvars) ORDER=A KEY=VALUE EMPTY=INCLUDE MISSING=EXCLUDE !IF (!title<>!NULL) !THEN /TITLES TITLE=!QUOTE(!UNQUOTE(!EVAL(!title))) !IFEND


* EOF *. --- schnipp ----

As a lot of you responded to me a lot of you think the macros are to complicated designed and to complicated to use. I agree concerning the amount of code that has to be implemented into each syntax file or even into include files for syntax. Therefore I would like to suggest to SPSS Inc. to create a facility in SPSS which makes it possible to compile tested macro code (as a single macro in a single file or even as multiple macros in single file which could be called as a macro library) and use it like an integrated command of SPSS, for example the FREQUENCIES command. Flexible programmed macros could be used by anybody as it if common with todays higher programming languages like "C".

I would be glad if the macro will be useful to you and if I could give some valueable ideas to the further development of the SPSS software package.

Best regards

Georg Maubach Market Analyst MRSC Division Corporate & MRSC-Services

Deutsche Post World Net Business Consulting GmbH Market Research Service Center

Back to: Top of message | Previous page | Main SPSSX-L page