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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.