Help using Base SAS procedures

Improve on Npar1way looping

Posts: 36

Improve on Npar1way looping


I am analyzing differences in data generated by different surveys. I have a couple of thousand variables and 10 survey versions. I compare variable by variable with proc npar1way, and I want to automate this procedure.

The problem with npar1way is that it quits as soon it discovers a variable having values with only one level at the chosen class variable. The procedure does not continue, but quits instead. So it seems I need to take away those variables in the first place.

Here is an example of doing this, but it is not fool proof, because the "proc tabulate" adds a "_N" at the end of all variable  names. This macro will fail on variables already being 32 characters wide. Can it be improved or made over?

%macro qc_loopitem(module);
title &module;
data npar1way_&module (keep = &module: survey_version); set x; run;
%charToNumeric(work, npar1way_&module, &module);

proc tabulate data = npar1way_&module order = freq out = tmp_npar1way_&module;
class survey_version;
var &module:;
table survey_version, n * &module:;
data tmp_npar1way_&module; set tmp_npar1way_&module; array module(*) &module:; do i = 1 to dim(module); call symput(cat("mod", i), ' '); call symput('n', i); if module = 0 then call symput(cat("mod", i), vname(module)); end; run;
%macro qc_dropvar; data tmp_npar1way_&module (drop = %do i = 1 %to &n; &&mod&i %endSmiley Wink; set tmp_npar1way_&module; run; %mend; %qc_dropvar;

proc sql noprint;
select substr(trim(name), 1, index(name, '_N') - 1) into :modulestr separated by ' '
from dictionary.columns where libname = 'WORK' and memname = "%upcase(tmp_npar1way_&module)" and (name like "&module.%");

proc npar1way data = npar1way_&module wilcoxon median;

class survey_version;
var &modulestr:;
output out = npar1way_&module;


%macro qc_loop;
%do i = 1 %to %sysfunc(countw(&ka_modules)); %qc_loopitem(%scan(&ka_modules, &i, ' ')); %end;
data npar1way; set npar1way_:; run;
proc datasets lib = work nolist; delete npar1way_: tmp_npar1way_:; run; quit;

Respected Advisor
Posts: 3,777

Re: Improve on Npar1way looping

Show some sample data with a few variables and enough obs to demonstrate the problem data and good data.

I think you will want to transpose the variables to observations so you can run PROC NPAR1WAY by "variable name";  this should be easier and faster.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation