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
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;
You can use call missing. e.g.,
call missing(textvar)
would work as would
call missing(numvar)
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
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;
Thanks Art
Steve
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;
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 ) ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.