MACRO ROW UNIV

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen

Zurück

Übersicht

Vorwärts

Source

%MACRO ROW_UNIV(dsn=,context=,by=,var=,stats=N NMISS,misscol=) / store des="Calculate values for continuous variables";
%LOCAL name n_lst v_lst i;
%LET name=ROW_UNIV;
%GLOBAL CURBY CURDSN CURMISS CURCON CURSTATS;
%LET curby=&BY;
%LET curdsn=&DSN;
%LET curcon=&CONTEXT;
%LET curmiss=&MISSCOL; 
%LET curstats=&STATS;
%CHK_LIST(list=&CURSTATS);
%IF &DSN ne and &BY ne and &VAR ne and &STATS ne and &MISSCOL ne %THEN %DO;
proc univariate
data=&DSN
 %IF %UPCASE(&MISSCOL) eq N %THEN
     (where=(&BY is not missing));
  noprint
  ;
  by
 %IF &CONTEXT ne %THEN
     &CONTEXT;
     &BY;
 var &VAR;
  output out=univ
 %DO I = 1 %TO &N_LST;
   %SCAN(%SCAN(&V_LST,&I,"|"),1,"#") =
   %SCAN(%SCAN(&V_LST,&I,"|"),1,"#")
 %END;
  ;
run;
proc sql;
  create table order as
  select &BY
 %IF &CONTEXT ne %THEN
       , &CONTEXT;
 %DO I = 1 %TO &N_LST;
       , %SCAN(%SCAN(&V_LST,&I,"|"),1,"#")
 %END;
  from univ
  ;
quit;
proc transpose
     data =   order
     out =    work.&NAME(drop=_LABEL_ rename=(_NAME_=STAT))
     prefix = VAL;
 %IF &CONTEXT ne %THEN
  by &CONTEXT; ;
 var
 %DO I = 1 %TO &N_LST;
   %SCAN(%SCAN(&V_LST,&I,"|"),1,"#")
 %END;
 ;
run;
%PUT &NAME._MESSAGE: Global macrovariables created: ;
%PUT &NAME._MESSAGE: CURBY (current column variable used) = &CURBY ;
%PUT &NAME._MESSAGE: CURDSN (current dataset used for read) = &CURDSN ;
%PUT &NAME._MESSAGE: CURMISS (Create column for missing values) = &CURMISS ;
%PUT &NAME._MESSAGE: CURSTATS (current statistics requested) = &CURSTATS ;
%IF &CURCON ne %THEN %DO; 
%PUT &NAME._MESSAGE: CURCON (current context if subset used) = &CURCON ;
%PUT &NAME._MESSAGE: Processing context is "&CONTEXT = &CURVAL(&CURLAB)". ;
%END;
%PUT &NAME._MESSAGE: Reading data from %UPCASE(&DSN). ;
%PUT &NAME._MESSAGE: Output dataset %UPCASE(work.&NAME) created. ;
%PUT ;
%END;
%ELSE %DO;
%PUT vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
%PUT &NAME._ERROR: Insufficient or missing Keyword Parameter(s).;
%PUT &NAME._STATUS: Macro processing abended. ;
%PUT &NAME._STATUS: Output dataset %UPCASE(work.&VAR) NOT created. ;
%PUT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
%GEN_MAIL(name=&NAME,rc=1);
%END;
%MEND ROW_UNIV;