%macro filter_and_print(dataset, new_dataset, var_id);
%local dsid varnum varname;
/* Open the dataset */
%let dsid = %sysfunc(open(&dataset));
/* Check if dataset is opened successfully */
%if &dsid %then %do;
/* Get the number of variables in the dataset */
%let varnum = %sysfunc(attrn(&dsid, nvars));
/* Loop through variables */
%do i = 1 %to &varnum;
/* Get variable name and type */
%let varname = %qscan(%sysfunc(varname(&dsid, &i)), 1);
/* Create filtered dataset */
data &new_dataset;
set &dataset;
if missing(&varname);
run;
/* Print filtered dataset */
proc print; var &var_id &varname;
run;
%end;
/* Close the dataset */
%let dsid = %sysfunc(close(&dsid));
%end;
%else %put ERROR: Unable to open dataset &dataset;
%mend;
So for this code, I would like to add the listvar parameter you mentioned. So ideal scenario: Do the PROC FREQ and NLEVELS to see what variables have missing values like was mentioned before.
Run the macro I am working on and specify the list of variables that we are going to be filtering by and printing the results for each variable. I know I can just make a new dataset while using KEEP=var_id listvar and then run the macro with the new dataset. I am really interested though in just making something that can do that last part for ease of use in the initial macro.
... View more