BookmarkSubscribeRSS Feed
blackraven
Fluorite | Level 6

Hi.

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:;
run;
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 %end;); 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.%");
quit;

proc npar1way data = npar1way_&module wilcoxon median;

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

%mend;


%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;
%mend;
%qc_loop;

1 REPLY 1
data_null__
Jade | Level 19

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 795 views
  • 0 likes
  • 2 in conversation