Write missing values as a dot
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | SPSS AnswerNet: Result Solution ID: 100000572 Product: SPSS Base Title: Writing an ASCII data file so SYSMIS is displayed as a period Description: Q. I need to create a raw ASCII file with dots replacing all missing values. I attempt to use WRITE command but I always get spaces instead of a period. When I then read the file with my other application I receive an incorrect result since the other program skips over the spaces. I would also like to create an ASCII file consisting only of the variable names from SPSS. A. First check to see if the other application can read a tab-delimited file with embedded blanks. If it can, then the program can be written very simply as follows. * ASSUME THE FILE IS ACTIVE AND IS ALL NUMERIC *. * Back up system file * . SAVE OUTFILE 'TMP.SAV'. * Change all missing values to SYSMIS *. RECODE ALL (MISSING=SYSMIS). SAVE TRANSLATE OUTFILE 'SPSS.DA'/TYPE=TAB /REPLACE. SELECT IF $CASENUM=1. FLIP . WRITE OUTFILE 'SPSS.TI' / CASE_LBL. EXECUTE. GET FILE 'TMP.SAV'. If the other application is unable to read a TAB delimited file then the task becomes more complicated but is still solvable. The trick is to change all values in the file to strings and then replacing blank strings with a period prior to writing the data. The simplest way I know of is to use SPSS to write the appropriate transformation syntax and then include this syntax. The main idea behind the generated syntax is to COMPUTE strings from the numeric variables. Drop the original numeric variables and rename the new strings to match the names of the numeric fields. One could also apply a STRING template to the variables and then write the file (after recoding blanks to '.'). * Back up the system file * . SAVE OUTFILE 'TMP.SAV'. * Get the variable names * . SELECT IF $CASENUM=1. FLIP. COMPUTE =1. COMPUTE ID=$CASENUM. STRING NEW (A8). COMPUTE NEW=CONCAT('VAR',STRING(ID,N5)). * Tag first and last variables for special processing *. MATCH FILES FILE * / LAST= BOT /FIRST=TOP / BY . * Generate a set of compute statements to change numerics to strings *. WRITE OUTFILE 'MCR0.TMP'/'STRING ',NEW, '(A8)'/ 'COMPUTE ',NEW,'=STRING(',CASE_LBL,',F8.4)' . * Generate a DROP statement *. DO IF TOP. WRITE OUTFILE 'MCR1.TMP' / 'MATCH FILES / FILE=* /DROP'. END IF. WRITE OUTFILE 'MCR1.TMP' /' ',CASE_LBL. * Generate a rename statement *. WRITE OUTFILE 'MCR2.TMP'/ 'RENAME VARIABLES ('NEW,'=',CASE_LBL,')'. * Generate file with variable names file *. WRITE OUTFILE 'SPSS.TI' / CASE_LBL. DO IF BOT. WRITE OUTFILE 'MCR2.TMP' /"WRITE OUTFILE 'SPSS.DA'/ALL (",ID (F3.0),'(A8,X))'. END IF. EXECUTE. GET FILE 'TMP.SAV'. RECODE ALL (MISSING=SYSMIS). INCLUDE 'MCR0.TMP'. INCLUDE 'MCR1.TMP'. RECODE ALL (' '='.'). INCLUDE 'MCR2.TMP'. EXECUTE. GET FILE 'TMP.SAV'. ERASE FILE 'MCR0.TMP'. ERASE FILE 'MCR1.TMP'. ERASE FILE 'MCR2.TMP'. |
Related pages
...