missing values in sas
play

Missing Values in SAS Magnus Mengelbier Director PhUSE 2011 1 - PowerPoint PPT Presentation

Missing Values in SAS Magnus Mengelbier Director PhUSE 2011 1 Topics Introduction Missing values Missing system option Assign missing values Tests for a missing value Summary PhUSE 2011 2 Question


  1. Missing Values in SAS Magnus Mengelbier Director PhUSE 2011 1

  2. Topics Introduction § Missing values § Missing system option § Assign missing values § Tests for a missing value § Summary § PhUSE 2011 2

  3. Question if myvar = . then put "I am missing" ; if myvar = "" then put "I am missing" ; if myvar = " " then put "I am missing" ; PhUSE 2011 3

  4. Missing Values data _null_ ; length char $ 10 ; num=. char=. num = . ; num is missing char = put( num, 8.-L); put num = / char = ; if missing(num) then put "num is missing"; if missing(char) then put "char is missing"; run; PhUSE 2011 4

  5. Default Value is a Missing Value data _null_; 81 data _null_; num_3 = w; 82 83 num_3 = w; put w = / num_1 = / num_2 = / num_3 = ; 84 85 put w = / num_1 = / num_2 = / num_3 = ; run; 86 87 run; NOTE: Variable w is uninitialized. NOTE: Variable num_1 is uninitialized. NOTE: Variable num_2 is uninitialized. w=. num_1=. num_2=. num_3=. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds PhUSE 2011 5

  6. Missing Codes data _null_ ; num = .B ; if ( num = . ) then put "num is missing"; 65 data _null_ ; if missing( num ) then put "missing() thinks num is missing"; 66 run; 67 num = .B ; 68 69 if ( num = . ) then put "num is missing"; 70 if missing( num ) then put "missing() thinks num is missing"; 71 run; missing() thinks num is missing NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds PhUSE 2011 6

  7. Missing System Option option missing = 'w'; § Single Character § “Format” of missing values § Only applicable to output PhUSE 2011 7

  8. Missing System Option – Example I option missing = ''; data _null_ ; length char $ 10 ; num= char= num = . ; num is missing char = put( num, 8.-L); char is missing put num = / char = ; if missing(num) then put "num is missing"; if missing(char) then put "char is missing"; run; option missing = '.'; PhUSE 2011 8

  9. Missing System Option – Example II data work.missing ; num_1 = .; num_2 = .B; 96 run; 97 option missing = 'w'; 98 option missing = 'w'; 99 data _null_; 100 set work.missing ; data _null_; 101 set work.missing ; 102 put num_1 = / num_2 = ; 103 put num_1 = / num_2 = ; 104 num_3 = w; 105 run; num_3 = w; run; NOTE: Variable w is uninitialized. num_1=w option missing = '.'; * reset the missing to be a period again ; num_2=B NOTE: There were 1 observations read from the data set WORK.MISSING. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds PhUSE 2011 9

  10. Assign Missing Values data _null_; call missing( num_1, num_2, w ) ; num_3 = w; 122 data _null_; 123 put num_1 = / num_2 = / num_3 = ; 124 call missing( num_1, num_2, w ); 125 num_3 = w; run; 126 127 put num_1 = / num_2 = / num_3 = ; 128 129 run; num_1=. num_2=. num_3=. NOTE: DATA statement used (Total process time): real time 0.05 seconds cpu time 0.01 seconds PhUSE 2011 10

  11. Tests for Missing Values Function Types Description missing() Numeric Tests if a single variable is missing. Character nmiss() Numeric Number of variables in the specified list with a missing value n() Numeric Number of variables in the specified list with a non-missing value cmiss() Numeric Number of variables in the specified list with a missing value Character Introduced in SAS 9.2 if missing( cats(char_1 , char_2 )) then put "all of them are missing"; PhUSE 2011 11

  12. Summary Missing values are valid values in SAS § Conversion of missing values § SAS System Option § Assign missing values § Ø “Period” notation Ø Missing Codes Ø CALL MISSING() Testing for missing values § Ø MISSING() Ø NMISS() Ø N() Ø CMISS() Consistent inconsistency § PhUSE 2011 12

  13. Questions & Comments Magnus Mengelbier Introduction § Director Missing values § Limelogic Ltd Missing system option § mmr@limelogic.com Assigning missing values § +44 208 144 5701 Testing for a missing value § Conclusion § PhUSE 2011 13

  14. T H E E N D PhUSE 2011 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend