Hello
How can i get the name of all missing variables raw by raw. thx
example
var1 var2 var3 var4 deriver_var
. 1 2 3 var1
2 . . 4 var2 var3
. . 4 . var1 var2 var4
data want;
set have;
length deriver_var $50;
array vars(*) var1-var4;
do _n_=1 to dim(vars);
if missing(vars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(vars(_n_)));
end;
end;
run;
Art, CEO, AnalystFinder.com
data want;
set have;
length deriver_var $50;
array vars(*) var1-var4;
do _n_=1 to dim(vars);
if missing(vars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(vars(_n_)));
end;
end;
run;
Art, CEO, AnalystFinder.com
Thanks
Dear Art,
how can I modify the code to get the deriver_var in a data set with several numeric and character variables like the attached example?
all your help will be appreciated
Thanks
Ed
I was unable to view your workbook, but here is one way to include both character and numeric variables:
data class;
set sashelp.class;
if _n_ in (2,8) then do;
call missing(age);
call missing(sex);
call missing(weight);
end;
run;
data want;
set class;
length deriver_var $50;
array cvars(*) name sex;
array nvars(*) age height weight;
do _n_=1 to dim(cvars);
if missing(cvars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(cvars(_n_)));
end;
end;
do _n_=1 to dim(nvars);
if missing(nvars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(nvars(_n_)));
end;
end;
run;
You could specify the numeric variables with _numeric_ rather than spelling them out. Unfortunately, you can't do the same with the character variables as deriver_var will be included in the list of character variables.
Art, CEO, AnalystFinder.com
You could use _character_ and just exclude the new variable from the check. e.g.:
data class;
set sashelp.class;
if _n_ in (2,8) then do;
call missing(age);
call missing(sex);
call missing(weight);
end;
run;
data want;
set class;
length deriver_var $50;
array cvars(*) _character_;
array nvars(*) _numeric_;
do _n_=1 to dim(cvars);
if vname(cvars(_n_)) ne 'deriver_var' and missing(cvars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(cvars(_n_)));
end;
end;
do _n_=1 to dim(nvars);
if missing(nvars(_n_)) then do;
deriver_var=catx(' ',deriver_var,vname(nvars(_n_)));
end;
end;
run;
Art, CEO, AnalystFinder.com
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.