Is there something like a DO IF/END IF for freqs and crosstabs?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there something like a DO IF/END IF for freqs and crosstabs?

parisec
Hi All,

This seems like a simple problem yet i am fumbling. Ultimately, I would like separate output files for 20 different sites. Each site has a SITE ID. The report consists of a few frequency tables and some crosstabs.

My first try was to use SPLIT FILE. This doesn't give me separate files and it doesn't even give me headings for each table for each site. The first site gets the "Frequency" "Percent", and "Valid Percent" headings but the rest of the sites get nothing but the table of numbers.

My second try was to use DO IF SITE ID = x, run the freqs and crosstabs,  END IF and use OUTPUT SAVE for each site. Perfect! but you are all chuckling at this foolishness since you already knew that DO IF and END IF don't work with FREQS and crosstabs.

My last resort is to go the route of TEMP SELECT IF commands before every single FREQ and CROSSTABS. This is ugly, will make me tear my hair out,  and I won't get separate output files but hey, i'll at least get headers on the tables for each site and i can separate the output manually.

Is there i'm missing that my current version 21 with no plugins can do to accomplish this task. I have read a bit about the SPSSINC SPLITDATASET extension but it'll take some calls to I.T. to get anything loaded.  I've also never run a macro but it may beat tearing out my hair ;-).

Thanks for any words of wisdom anyone might have.
Carol

Reply | Threaded
Open this post in threaded view
|

Re: Is there something like a DO IF/END IF for freqs and crosstabs?

Jon Peck
The SPSSINC SPLIT DATASET and SPSSINC PROCESS FILES can handle this scenario.  SPLIT DATASET creates a set of sav files based on a splitting variable like SPLIT FILES.  Then PROCESS FILES can apply a syntax file to each of the datasets.  This lets you run groups of procedures over each split, hence grouping the output.  And you can choose whether to have a single Viewer file with all the output or a separate file for each.

SPLIT DATASET on the menus is Data > Split into Files, and PROCESS FILES is Utilities > Process Data Files.
These can be installed from the Utilities or Extensions (V24) menus if you don't already have them.  In both cases, syntax help is also available by placing the cursor on an instance in the Syntax Editor and pressing F1 (V23 or later) or running, e.g., SPSSINC SPLIT DATASET /HELP.

In setting up the syntax for PROCESS FILES to apply, note that PROCESS FILES defines file handles and macros before it invokes the syntax file each time.  You use those to open the data file and possibly to create names for various outputs.


On Fri, Sep 2, 2016 at 10:21 AM, parisec <[hidden email]> wrote:
Hi All,

This seems like a simple problem yet i am fumbling. Ultimately, I would like
separate output files for 20 different sites. Each site has a SITE ID. The
report consists of a few frequency tables and some crosstabs.

My first try was to use SPLIT FILE. This doesn't give me separate files and
it doesn't even give me headings for each table for each site. The first
site gets the "Frequency" "Percent", and "Valid Percent" headings but the
rest of the sites get nothing but the table of numbers.

My second try was to use DO IF SITE ID = x, run the freqs and crosstabs,
END IF and use OUTPUT SAVE for each site. Perfect! but you are all chuckling
at this foolishness since you already knew that DO IF and END IF don't work
with FREQS and crosstabs.

My last resort is to go the route of TEMP SELECT IF commands before every
single FREQ and CROSSTABS. This is ugly, will make me tear my hair out,  and
I won't get separate output files but hey, i'll at least get headers on the
tables for each site and i can separate the output manually.

Is there i'm missing that my current version 21 with no plugins can do to
accomplish this task. I have read a bit about the SPSSINC SPLITDATASET
extension but it'll take some calls to I.T. to get anything loaded.  I've
also never run a macro but it may beat tearing out my hair ;-).

Thanks for any words of wisdom anyone might have.
Carol





--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Is-there-something-like-a-DO-IF-END-IF-for-freqs-and-crosstabs-tp5733038.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Is there something like a DO IF/END IF for freqs and crosstabs?

Bruce Weaver
Administrator
In reply to this post by parisec
DISCLAIMER:  Jon is going to hate this--sorry Jon.  

For a relatively simple situation like this with one split variable (Site) and consecutive values in a known range, I think a macro works pretty neatly.  Here's a (simple, I hope) example that uses the survey_sample.sav file from the /SAMPLES folder.


NEW FILE.
DATASET CLOSE ALL.

* Change path to your /Samples folder.
GET FILE = "C:\SPSSdata\survey_sample.sav".

* Generate a phony site variable with 5 sites.
* Don't do this if you already have a Site variable.
COMPUTE Site = MOD($CASENUM,5).
FORMATS Site(F5.0).
RECODE Site (0=5).
FREQUENCIES Site.

* Define a macro.
DEFINE !MySplit
 ( !POS !TOKENS(1) /
   !POS !TOKENS(1) )

!DO !Site = !1 !TO !2
OUTPUT NEW.
!LET !OutputName = !CONCAT("Site",!Site)
OUTPUT NAME !OutputName.
COMPUTE @Filter@ = (Site EQ !Site).
USE ALL.
FILTER BY @Filter@.
*****************************************.
* The actual analyses of interest .
*****************************************.
!LET !Title = !CONCAT("SITE = ",!Site)
TITLE !QUOTE(!Title).
FREQUENCIES degree.
DESCRIPTIVES age educ.
* Etc.
* Add OUTPUT SAVE & OUTPUT CLOSE commands here if you like.
*****************************************
USE ALL.
FILTER OFF.
!DOEND
!ENDDEFINE.

* Call the macro with positional arguments indicating
* first and last values of the Site variable.
!MySplit 1 5.


HTH.


p.s. - Even with 2 or 3 split variables, it would be a simple matter of nesting the !DO loops.

!DO !Split1 = !1 !TO !2
!DO !Split2 = !3 !TO !4
!DO !Split3 = !5 !TO !6
*The guts of the macro here.
!DOEND
!DOEND
!DOEND



parisec wrote
Hi All,

This seems like a simple problem yet i am fumbling. Ultimately, I would like separate output files for 20 different sites. Each site has a SITE ID. The report consists of a few frequency tables and some crosstabs.

My first try was to use SPLIT FILE. This doesn't give me separate files and it doesn't even give me headings for each table for each site. The first site gets the "Frequency" "Percent", and "Valid Percent" headings but the rest of the sites get nothing but the table of numbers.

My second try was to use DO IF SITE ID = x, run the freqs and crosstabs,  END IF and use OUTPUT SAVE for each site. Perfect! but you are all chuckling at this foolishness since you already knew that DO IF and END IF don't work with FREQS and crosstabs.

My last resort is to go the route of TEMP SELECT IF commands before every single FREQ and CROSSTABS. This is ugly, will make me tear my hair out,  and I won't get separate output files but hey, i'll at least get headers on the tables for each site and i can separate the output manually.

Is there i'm missing that my current version 21 with no plugins can do to accomplish this task. I have read a bit about the SPSSINC SPLITDATASET extension but it'll take some calls to I.T. to get anything loaded.  I've also never run a macro but it may beat tearing out my hair ;-).

Thanks for any words of wisdom anyone might have.
Carol
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Is there something like a DO IF/END IF for freqs and crosstabs?

Art Kendall
? SPLIT FILE Separate BY Varlist ...
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Is there something like a DO IF/END IF for freqs and crosstabs?

Bruce Weaver
Administrator
Hi Art.  Carol wants "a few frequency tables and some crosstabs" for each site, with all of the output for a site grouped together and in a separate output window.  SPLIT FILES will not give this.  It will give output split by site for each command separately.  

Cheers,
Bruce

Art Kendall wrote
? SPLIT FILE Separate BY Varlist ...
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Is there something like a DO IF/END IF for freqs and crosstabs?

parisec
Hi all,

Jon lead me to the python well and i drank the kool aid. It was a week of working with I.T. to get the extension installed correctly and another several days of jon answering my "why isn't this working" questions. But this was the successful code that did the job

SPSSINC SPLIT DATASET SPLITVAR=newSiteID
   /output directory = "g:\saveoutputfileshere" deletecontents=no.
SPSSINC PROCESS Files
   INPUTDATA =  "g:\split up the main file and save them here\*.sav"
   *SYNTAX =  "g:\run this syntax on each of the individual site files\SiteSpecificSyntax.sps"
   VIEWERDIR =  "g:\save the .spv files here\Individual site files\SiteOutput".
 
*in the syntax file  - this is the first line
get file="JOB_INPUTFILE".

Art, i really like the ease of split files and that was my first option. The downfall of this is that it doesn't split up the output files.

Bruce, after 2 unsuccessful installs of the extension, i almost gave up and went with your macro route. Thank you for posting this.

Thank you jon for your assistance. This extension is going to come in handy.

Carol