SPSS ignore error (script?)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SPSS ignore error (script?)

Jara Kampmann
Dear List,

I wrote a syntax (see below) to get an item-non-response table automatically transferred to excel. It works with a macro, as I want to use this syntax job automatically for approx. 40 data sets in a row (on about 400 variables).
The good news: it works like that.
The bad news: as soon as a data set does not include one of the variables to be processed I get an error message and the procedure for this data set is not run, resulting in no output for the whole data set (however for the next data sets).

I reckon that there is a possibility to get SPSS to ignore an error and go on with the next variable. I found this snipped of script:
Sub main
on error GoTo X

X:  Debug.Print "Err=";Err
    Err.Clear
    Debug.Print "Err=";Err
    Resume Next
End Sub

of which I assume it would somehow do the trick. Preferably I would like SPSS in case of an error to fill in something like the string "Err" instead of filling in the value. And most importantly to go on with the procedure for the next variable of the same data set.

The big obstacle is that I do not have any experience with scripts and therefore no idea how and where to apply it in my syntax.

Has anyone an idea what to include in my syntax and also where?

For any help I would be majorly thankful.
Best wishes,
Jara


Syntax (with subsample of data sets and variables):


DEFINE !PATH ()
"I:/NDS/"
!ENDDEFINE.

DEFINE !datasets ()
"AL_v0-2-0.sav"
"AM_v0-2-0.sav"
!ENDDEFINE.

define !varlist_n ()
v109 v110 v132
!enddefine.


*OMS for INR-table to excel*
OMS
  /SELECT TABLES
  /IF COMMANDS=['CTables'] SUBTYPES=['Custom Table']
  /DESTINATION FORMAT=XLS
   OUTFILE='C:\oms_ctable2.xls'
  /COLUMNS DIMNAMES=["r1"]
  /TAG='NDS'.


DEFINE !data (KEY1=!charend('/') / KEY2=!charend('/') / varlist =!charend ('/') / KEY3=!cmdend).

*open data set*
!do !x !in (!key1).
!LET !path_unq=!UNQUOTE(!KEY3).
!LET !key1_unq=!UNQUOTE(!x).
!LET !pathdata = !CONCAT(!path_unq , !KEY1_unq).
GET FILE =!QUOTE(!pathdata).

*create list of variables with "+" inbetween*
!let !flaglist = "".
!do !y !in(!varlist).
!let !flag = !concat(!y,"_inr1").
!let !flaglist = !concat(!flaglist,!flag," + ").
compute !flag = !y.
execute.
!doend.

*create INR table for according data set(!x)*
ctable
/ table (!flaglist v132) [MISSING]
/TITLES TITLE= !x.
EXECUTE .

!doend.
!ENDDEFINE.

!data  varlist = !varlist_n /  KEY1= !datasets / KEY2=!cnt_varlist / KEY3=!path .

*OMSEND.
OMSEND TAG=['NDS'].

=====================
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