DATA Step, Macro, Functions and more

Assigning Missing Values Irrespective of Type

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Assigning Missing Values Irrespective of Type

Hi

Is it possible to assign values to missing without knowing the variable's type?

A function that would assign a '' or . itself and I do not have to explicitily type it.  I have some variables and do not want to have to find out which each type is  and then assign them either '' or . myself.

Something like

     textvar=missing;

     numvar=missing;

ie set it to the appropriate missing value

Thanks in advance

Steve


Accepted Solutions
Solution
‎10-31-2011 09:23 AM
PROC Star
Posts: 7,467

Assigning Missing Values Irrespective of Type

There are some shortcuts you could use, but the brute force method of applying call missing might be:

data .....;

set.....;

if not first.subject then do;

     call missing(age);

     call missing(sex);

     call missing(telno);

     call missing(address);

end;  

run;

View solution in original post


All Replies
PROC Star
Posts: 7,467

Assigning Missing Values Irrespective of Type

You can use call missing.  e.g.,

call missing(textvar)

would work as would

call missing(numvar)

Contributor
Posts: 51

Assigning Missing Values Irrespective of Type

Thanks Art...

sorry but don;t really understand.  Do you have an example

Maybe it will be clearer when I give an example too..

data .....;

set.....;

if not first.subject then do;

     age=.;

     sex=.;

     telno='';

     address='';

end;   

run;

Thanks

Steve

Solution
‎10-31-2011 09:23 AM
PROC Star
Posts: 7,467

Assigning Missing Values Irrespective of Type

There are some shortcuts you could use, but the brute force method of applying call missing might be:

data .....;

set.....;

if not first.subject then do;

     call missing(age);

     call missing(sex);

     call missing(telno);

     call missing(address);

end;  

run;

Contributor
Posts: 51

Assigning Missing Values Irrespective of Type

Thanks Art

Steve

PROC Star
Posts: 7,467

Assigning Missing Values Irrespective of Type

And, depending upon what you want to do, you can use call missing with arrays.  E.g., while the following probably isn't close to your problem, it may show you some of the versatility.  It takes sashelp.class and, for every other record, either sets the character fields or the numeric fields to missing:

data test;

  set sashelp.class;

  array numbers(*) _numeric_;

  array characters(*) _character_;

  if mod(_n_,2) eq 1 then do;

    call missing(of numbers(*));

  end;

  else do;

    call missing(of characters(*));

  end;

run;

Valued Guide
Posts: 2,177

Assigning Missing Values Irrespective of Type

shortcuts that Art297 refers to are great try

if not first.subject then call missing( age, sex, telno, address );

or

%let varlist = age sex telno address ;

if not first.subject then call missing( of &varlist ) ;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 202 views
  • 4 likes
  • 3 in conversation