BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

You can now use the GETOPTION() function to retrieve the current setting for System options like MPRINT or NOTES. But that does not cover the settings you made using the MISSING statement.  

 

What is the MISSING statement?

 

It allows you to control which single letter values the numeric informat will interpret as representing the associated special missing value.  Here is an example usage from the documentation page.

 

With survey data, you might want to identify certain types of missing data. For example, in the data, an A can mean that the respondent is not at home at the time of the survey; an R can mean that the respondent refused to answer. Use the MISSING statement to identify to SAS that the values A and R in the input data lines are to be considered special missing values rather than invalid numeric data values:

missing a r;
data survey;
   input id answer;
datalines;
001 2
002 R
003 1
004 A
005 2
;

 

One way to determine if a particular letter has been included in the MISSING statement settings is to try to read that letter and check if the result is regular missing or special missing.

 

Here is a macro that can be used to do that for every special missing value and return the resulting list as the results of the macro call.

%macro missing;
/*----------------------------------------------------------------------------
Return current MISSING statement settings
----------------------------------------------------------------------------*/
%local missing rc;
%let rc=%sysfunc(dosubl(%nrstr(
options nonotes;
data _null_;
  missing='_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  do i=1 to 27;
    if .=input(char(missing,i),??1.) then substr(missing,i,1)=' ';
  end;
  call symputx('missing',compress(missing,' '));
run;
)));
&missing.
%mend missing;

 

Using this macro you can save and later restore the current state of the MISSING statement.

 

Now we can update the example from the documentation page to prevent it from having a side effect of changing the MISSING statement settings for the rest of your program.

 

Just save the current settings to a macro variable and then use the macro variable to restore the MISSING statement settings.

%let misssave=%missing;
missing a r;
data survey;
   input id answer;
datalines;
001 2
002 R
003 1
004 A
005 2
;
missing &misssave;

 

2 REPLIES 2
Quentin
Super User

Nice tip, thanks for sharing.

 

It looks like the value set my the MISSING statement is likely shared between the main session and the DOSUBL side session.  If you change the value in the side session, the changed value is also seen in the main session.

 

Which is different than (most?) system options, which I think typically the side session will inherit the value of system options from the main session, but side session options seem to be independent of the main session options, and changes made to side session options do not typically propagate back to the main session (from my limited testing).

 

missing A B C ;
options firstobs=3 ;

%put main session missing: %missing();
%put main session firstobs: %sysfunc(getoption(firstobs));


data _null_ ;
  rc=dosubl(
'
%put side session missing before assignment: %missing();
%put side session firstobs before assignment: %sysfunc(getoption(firstobs));
missing D E F;
options firstobs=9 ;
%put side session missing after assignment: %missing();
%put side session firstobs after assignment: %sysfunc(getoption(firstobs));
'
  ) ;
run ;

%put main session missing: %missing();
%put side session firstobs: %sysfunc(getoption(firstobs));

Returns:

main session missing: ABC
main session firstobs: 3

side session missing before assignment: ABC
side session firstobs before assignment: 3

side session missing after assignment: DEF
side session firstobs after assignment: 9

main session missing: DEF /*missing value was changed in main session*/
side session firstobs: 3  /*firstobs option was NOT changed in main session*/
Ksharp
Super User
Tom,
You should post it at Libary communitity:
https://communities.sas.com/t5/SAS-Communities-Library/tkb-p/library

And you need the help from @ ChrisHemedinger
or
@BeverlyBrown
to publish this useful tip/paper.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 700 views
  • 5 likes
  • 3 in conversation