Frequently Asked Questions about SPSS

Below you'll find answers to some of the questions listed on the SPSS FAQ page. The answers found here are only a small subset of those listed. Please visit the original FAQ page to search for more Frequently Asked Questions on SPSS.

Return to SPSS FAQ page

 

Q42. How can I use macros in SPSS?

        MACROS IN SPSS

The purpose of a macro is to provide a shorthand way to issue a series of commands.  The
commands will execute a standardized program after you provide information that customizes
it for your data set.
        
So for example, say you are working with 10 separate data sets.  For each one, you want to
generate frequencies, descriptive statistics and histograms for a series of variables.  In
SPSS, your command file would like something like:

GET FILE=
FREQUENCIES VAR=
  /STATISTICS=MEAN MODE MIN MAX
  /HISTOGRAMS
  
Well, instead of writing out these lines ten times, you could write one macro, called
MACROFREQ. Once you write this macro, all you would have to do is call up the macro and
provide the name of the systems file and variables you want to see frequencies for.

The process:
1.      First, define the macro.
        --      you begin with the line DEFINE MACRONAME;
        --      then you define "placeholders" for all of the pieces of information you
                will eventually provide from your particular data set.
        --      you tell the macro how it will know when you have finished providing the
                information for each placeholder;
2.      Second, you write out the commands you want the macro to run.
3.      Third, you end the macro with the line !ENDDEFINE
4.      Finally, you invoke the macro and provide the specific information for each
                "placeholder."


DEFINE MACROFREQ                        MEANS: I am going to write a macro and call it MACROFREQ;
  (sysfile=!charend (';')               MEANS: When I invoke MACROFREQ, I will provide the name
                                        of a systems file, followed by a ;
  /variables=!charend (';')             MEANS: I will also provide a list of variable names,
                                        followed by a ;   
  
                                        
Next come the command lines; they look just like regular SPSS commands, except that the
"placeholders" are used (preceded by an !) instead of actual file names and variable names.
    
GET FILE=!sysfile
    FREQUENCIES VAR=!variables          In other words, the lines are standardized, instead of
      /stat=mean mode min max           specific to an actual systems file or actual variables.
      /histograms
      
    !ENDDEFINE                          MEANS: I am finished defining the macro called MACROFREQ.
                
    
Now, you invoke the MACRO and provide the information that will customize it for your data.

MACROFREQ
  sysfile=itc.sys1;                     MEANS: substitute this systems filename any place !sysfile
                                        appears in the MACRO. The ; means "I'm finished typing the
                                        name of the file."
  variables=sex class test1 test2;      MEANS: substitute these variables any place !variables
                                        appears in the MACRO.  The ; means "I'm finished typing
                                        the list of variables."

    MACROFREQ                           invoke MACROFREQ;
      sysfile=itc.sys2;                 new sysfile name, ending with a ;
      variables=age race jobcode;       new variable list, ending with a ;
      
    MACROFREQ                           invoke MACROFREQ;
      sysfile=itc.sys3                  new sysfile name, ending with a ;
      variables=idnum hours vacation;   new variable list, ending with a ;
                
    etc...
Return to Top
--------------------------------------------------------------------------
Q43. I have a sample from a population for which some subgroups have been over- or undersampled. How can I do differential sample weighting for these subgroups? A: The WEIGHT command is used to weight cases differentially for analysis. The variable named after the keyword BY on the WEIGHT command is used to weight cases, as in WEIGHT BY wtfactor This tells SPSS to use value of variable wtfactor to weight cases. The following example assumes that the subgroups of AGE 19 and AGE 20 are undersampled by a factor of 2 and 3 respectively. Before the weighting, the numbers of cases in the subgroups AGE 19 and AGE 20 are 4 and 3 respectively, while after the weighting they are 8 and 9. TITLE 'Test whether can do diffential sample weighting'. SET WIDTH=80 /LENGTH =none. DATA LIST FIXED / name 1-8 (A) gender 9 age 11-12 wgt 14-16, hgt 18-21 (1) test1 TO test3 23-31. COMPUTE testotal= test1 + test2 + test3. MISSING VALUES gender (3) age (99) hgt (999) wgt (0) test1 to test3 (999). BEGIN DATA. george 1 18 190 68.5 600500560 richard 1 20 150 45.2 650620999 SAM 1 19 205 750 999 michael 1 180 58.6 400530620 clifford1 19 210 69.8 500640440 pat 20 145 473 600760700 susan 2 18 160 50.2 560490610 MARION 2 99 146 45.3 630650640 Joan 2 19 590460510 pamela 2 18 150 48.6 680630620 eve 2 20 165 50.8 610520490 PATRICIA2 19 99 55.3 590420610 END DATA. compute wvar2 = 4. if (age = 18) wvar2 = 1. if (age = 19) wvar2 = 2. if (age = 20) wvar2 = 3. LIST VARIABLES = name to wvar2. Frequencies variables = age, test1 /sta=default. weight by wvar2. frequencies variables = age, test1 /sta=default.

Return to Top


--------------------------------------------------------------------------
Q44/Q47/Q56. How do I transfer SPSS files between Mac and Windows?
SPSS 10 appears to function only in Classic Mac OS9 and not with the emulator in OSX.

An easy and convenient way to transfer files between Mac and Windows is with a zip disk. System (.sav and .por) and command (.sps) files may successfully be opened and edited in either platform, regardless of the platform in which it was originally saved. However, you will not be able to open in Mac an output file (.spo) that was originally saved in Windows, or vice versa. To view output files in either platform, click on File --> Export. Specify "All objects" and save the file as HTML.

Return to Top


--------------------------------------------------------------------------
Q45. SPSS System File into SPSS Transport File?


A.

/******************************************************************/
/*  PROGRAM: export.sps         By: Tim F.J. Tolson   Date: 9/95  */
/*                                                                */
/* Example program for converting a SPSS System file into a SPSS  */
/* TRANSPORT format file.  This transport file can be read by     */
/* SPSS on other computer systems (e.g., SPSS for Windows) as well*/
/* as by SAS, using the PROC CONVERT command                      */
/*                                                                */
/*  >>>> Please see the PROGRAM & SPECIAL NOTES at bottom <<<<    */
/******************************************************************/
 
TITLE 'Export SPSS system file to SPSS transport (por) file'.
 
SET LENGTH=NONE.  /* gets rid of page ejects to save paper */
 
GET FILE = 'anyname.sys' .
   /* Change "anyname.sys" to the name of your system file */
 
DISPLAY DICTIONARY .   /* shows variable names, labels, etc. */
DESCRIPTIVES ALL .     /* provides descriptive stats on all numeric vars */
 
EXPORT OUTFILE = 'anyname.por' /MAP .
  /* Change "anyname.por" to name you want the SPSS transport file to have */
  /*  the extension ".por" is recommend as that's a default extension  */
  /*  name for SPSS for Windows transport formatted files.             */
 
 /*  =========== INSTRUCTIONS for Using this FILE ===================  */
 /*      This file gives you the commands for exporting a SPSS system  */
 /*  file to a transport formatted system file.                        */
 /* *** VERIFYING and CHECKING your data for transfer ***************  */
 /*    The DISPLAY DICTIONARY lists all the information about the      */
 /*  system file.  It tells the variable names, type, any formats,     */
 /*  missing values and variables and value labels.                    */
 /*    DESCRIPTIVES gives the Mean, Standard Deviation, Minimum &      */
 /*  Maximum value for each variable in the system file.  Use these    */
 /*  two pieces of output to compare the current system file to the    */
 /*  system file AFTER you imported to the new computer to make        */
 /*  sure the data tranferred correctly.  It's one in 10,000 that it   */
 /*  does not, but you don't want to be the one!                       */  
 /*                                                                    */
 /*    The EXPORT command is what does the actual conversion from a    */
 /*  SPSS system file to a SPSS transport file.                        */
 /*  It is converting the SPSS system file from a format that is read- */
 /*  able only on this computer to a format that is readable by any    */
 /*  computer that is running SPSS and some versions of SAS            */
 /*                                                                    */
 /*   ************ IMPORTANT TRANSFER INFORMATION ******************** */
 /*    After you created the SPSS  transport file to disk, you MUST    */
 /*  transfer it in ASCII mode.                                        */
 /*    When you IMPORT the transport file use DISPLAY DICTIONARY and   */
 /*  DESCRIPTIVES commands to generate the same information generated  */
 /*  by this file and compare the results to the output from this job  */
 /*  to make sure the data transferred correctly.                      */
 /**********************************************************************/
 /* If you need assistance or have questions about this program        */
 /* contact the Statistical Computing Consultants at the ITC Help      */
 /* Desk by telephoning 924-3731 or by sending e-mail to               */
 /* Consult@Virginia.EDU                                               */  
 /**********************************************************************/

 

Return to Top

--------------------------------------------------------------------------
Return to SPSS FAQ page

© 2009 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.