Search code examples
sasspss

Translating a simple data check method from SAS into SPSS (crosstabs for 3+ variables fed into output dataset)


I am looking to see whether SPSS can do a specific thing that I often do in SAS, or something similar to it.

When I create a new categorical variable in SAS based on other existing variables I typically check that it was coded correctly and completely by looking at the "combinations" of values of the new and old variables, all crosstabulated at once and fed into an output dataset. The syntax I am referring to is this - In this case, imagine that I have programmed in newvar based on the combined values of oldvar1 and oldvar2, and my goal is to see if the results are as I would expect:

proc freq data=dataset2 noprint;
tables oldvar1*oldvar2*newvar / out=combinations;
run;

I then visually look at the combinations dataset and check if results are as expected. I use this method (proc freq with noprint and output a dataset) for other things as well. I am trying to teach my colleague how to more effectively check data and syntax, except I need to do so in SPSS, not SAS. Does anyone have any comparable methods that apply to SPSS, or is it possible to do this exact thing in SPSS?

Thank you!


Solution

  • Here are two ways to do it: The first one is to use crosstabs and see the results in the output window:

    crosstabs var1 by var2 by newvar.
    

    In the output window you can double click on the resulting table to play around with the pivoting trays and arrange the table in the most comfortable manner for you.

    A different way is to use aggregate:

    dataset declare checkhere.
    aggregate /outfile='checkhere' /break=var1 var2 newvar /n=n.
    dataset activate checkhere.
    

    The new dataset will contain the count for each possible combination of the three variables. Here you can move the columns and/or sort them in order to get your most comfortable setup.