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:         Tue, 20 Sep 2005 09:22:48 +0200
Reply-To:     Marta García-Granero
              <biostatistics@terra.es>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Marta García-Granero
              <biostatistics@terra.es>
Organization: Asesoría Bioestadística
Subject:      Re: syntax or macro to remove variables
In-Reply-To:  <6.0.0.22.2.20050919222629.04c0c0d0@mail.jp.pair.com>
Content-Type: text/plain; charset=ISO-8859-15

Hi Jeff,

This same question was answered time ago in this list. The following code will do the task, but date variables will loose their format, and string variables will be lost. If you save your original dataset first, you can apply the dictionary later to restore date variables format, and you can match the cleaned file with the original to recover any lost string variable.

* Example dataset with 6 variables & several missing data *. DATA LIST LIST/var1 TO var6. BEGIN DATA 1.0 7.5 -999 -999 -999 -999 1.0 6.2 -999 -999 -999 4 1.0 6.9 -999 -999 -999 -999 1.0 7.4 -999 -999 -999 -999 1.0 9.2 -999 -999 -999 -999 1.0 8.3 1 -999 -999 -999 1.0 7.6 -999 -999 -999 -999 2.0 5.8 -999 -999 -999 -999 2.0 7.3 -999 -999 -999 -999 2.0 8.2 -999 -999 -999 -999 2.0 7.1 -999 -999 -999 -999 2.0 7.8 -999 -999 -999 -999 2.0 7.2 -999 -999 -999 2 2.0 7.3 -999 -999 -999 -999 3.0 5.9 -999 -999 -999 -999 3.0 6.2 -999 -999 -999 -999 3.0 5.8 -999 -999 -999 -999 3.0 4.7 -999 -999 -999 -999 3.0 7.3 5 -999 -999 -999 3.0 7.2 -999 -999 -999 -999 3.0 6.2 -999 -999 -999 -999 4.0 6.2 -999 -999 -999 -999 4.0 6.8 -999 -999 -999 -999 4.0 5.7 -999 -999 -999 -999 4.0 4.9 -999 -999 -999 7 4.0 6.2 -999 -999 -999 -999 4.0 5.8 -999 -999 -999 -999 4.0 5.4 -999 -999 -999 -999 END DATA. RECODE var3 var4 var5 var6 (-999=SYSMIS) . EXECUTE . * All cases for var4 & var5 are sysmiss *.

STRING newvar(A8). COMPUTE newvar=CONCAT('f',LTRIM(STRING($CASENUM,F7))). PRESERVE. SET ERRORS=NONE RESULTS=NONE. FLIP /NEWNAME=newvar. COMPUTE xxx=$SYSMIS. COMPUTE ncases = NVALID(f1 TO xxx) . SELEC IF ncases NE 0. MATCH FILES FILE=* /DROP=ncases xxx. FLIP /NEWNAME=CASE_LBL . MATCH FILES FILE=* /DROP=CASE_LBL. EXEC. RESTORE.

J> I'm working with a fairly large data set and need to reduce the file size J> by removing a number of variables where the values for all records are J> system missing (these represent survey questions that weren't asked during J> the particular year of the survey I'm using). In the past, I've used the J> following syntax to remove a single known variable, but how would I write J> either simple syntax or a macro that would check each variable in the data J> and delete all that contained no data?

Regards, Marta mailto:biostatistics@terra.es


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