data colmiss_ds ;
infile datalines truncover;
input x y z a$ b$ ;
datalines;
1 . 66 BB
2 55 .
3 . . CC DD
4 55 .
;
run;
options symbolgen;
%macro xyz(new_ds,exist_ds,nvar,charvar);
data &new_ds;
set &exist_ds;
if nmiss(&nvar))=. then output;
if cmiss(&charvar))= '' then output;
%mend;
%xyz(dsn,colmiss_ds,nvar,charvar);
how to get numeric and character missing count using macro application
As Kurt said no need macro at all.
data colmiss_ds ;
infile datalines truncover;
input x y z a$ b$ ;
datalines;
1 . 66 BB
2 55 .
3 . . CC DD
4 55 .
;
run;
proc transpose data=colmiss_ds(obs=0) out=temp;
var _all_;
run;
proc sql noprint;
select catx(' ','nmiss(',_name_,') as',_name_) into :missing separated by ',' from temp;
create table temp2 as select &missing. from colmiss_ds;
quit;
proc transpose data=temp2 out=want;
run;
Before you engage in macro programming, start with working non-macro code.
So get rid of all the macro stuff and write a simple step which does what you do.
To get hints for this, also post the expected result for your example data.
As Kurt said no need macro at all.
data colmiss_ds ;
infile datalines truncover;
input x y z a$ b$ ;
datalines;
1 . 66 BB
2 55 .
3 . . CC DD
4 55 .
;
run;
proc transpose data=colmiss_ds(obs=0) out=temp;
var _all_;
run;
proc sql noprint;
select catx(' ','nmiss(',_name_,') as',_name_) into :missing separated by ',' from temp;
create table temp2 as select &missing. from colmiss_ds;
quit;
proc transpose data=temp2 out=want;
run;
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 16. 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.