BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
slolay
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

6 REPLIES 6
art297
Opal | Level 21

You can use call missing.  e.g.,

call missing(textvar)

would work as would

call missing(numvar)

slolay
Fluorite | Level 6

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

art297
Opal | Level 21

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;

slolay
Fluorite | Level 6

Thanks Art

Steve

art297
Opal | Level 21

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;

Peter_C
Rhodochrosite | Level 12

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 ) ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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