SAS data sets automatic test

OPTION  NOCENTER LS=MAX PS=MAX OBS=MAX MACROGEN;

LIBNAME A '.';

OPTIONS FMTSEARCH=(A);

    
/*附录宏*/
%MACRO M_APPENDIX_FORMAT(N1);
    
    %IF %INDEX(&LVARNAME,&N1.) %THEN %DO;
        %DO K=1 %TO &LA_LEN.;                                
            %LET AN=%SCAN(&LVARNAME.,&K.);
            %LET AC=%SCAN(&LA.,&K.);
            %IF &AN.=&N1. %THEN %DO;
                FORMAT &N1. $&AC._FMT.;
                
            %END;
        %END;
    %END;
    %ELSE %DO;
        FORMAT &N1. $3.;
    %END;
            
%MEND;


%LET NL=%SYSFUNC(COUNTW(&NLIST.));/*变量个数*/
% LET LVARNAME = IDENTITEY_TYPE BUSINESS_ORG_TYPE BUSINESS_TYPE PAYBACK_PERSON_TYPE CLASS5_STATE CURRENCY PAYMENT_STAUTS; / * Appendix variables * / 
% LET LA = A1 A18 the A20 A44 A58 A32 A33; / * variable corresponds Appendix * / 
% LET LA_LEN =% SYSFUNC (COUNTW (& LVARNAME).) ; 

% M_APPENDIX_FORMAT (IDENTITEY_TYPE); 

the LIBNAME XLS the EXCEL * .xls '36 '; 

% LET outputData = PCR_BASEINFO; 

% the MACRO the cHECK; 

	/ *. 1, check table structure - reserved field: variable number, the variable names, variable labels, variable type, variable length * / 
	the PROC = the CONTENTS A. & outputData the DATA OUT = temp_t1 (the LABEL the KEEP the TYPE NAME = VARNUM the lENGTH) the NOPRINT VARNUM; 
	the RUN; 
	
	the PROC the SORT the DATA = temp_t1; 
		BY VARNUM; 
	the RUN; 
	
	the DATA XLS.CONTENTS; 
		the SET temp_t1; 
	the RUN; 
	
	/ * 2, view 100 records before printing * / 
	the DATA XLS.TOP100;
		A. & outputData the SET (the OBS = 100); 
	the RUN; 
	
	/ *. 3, and relationships checking uniqueness checking * / 

	the PROC A. & outputData the SORT the DATA = (the KEEP = REPORT_NO IDENTITEY_TYPE BUSINESS_ORG_TYPE BUSINESS_ORG BUSINESS_TYPE) OUT = NODUP DUPOUT = XLS.REPORT_NO_DUP NODUPKEY ; 
	the QUIT; 
	% LET NL =% SYSFUNC (COUNTW (& NLIST).); / * number of variables * /
		REPORT_NO IDENTITEY_TYPE BUSINESS_ORG_TYPE BUSINESS_ORG BUSINESS_TYPE BY; 
	the RUN; 
	
	the DATA XLS.DATE_XC; 
		the SET A. & outputData; 
		the MON = INTCK ( "MONTH", open_date, PUTOUT_DATE); 
		the IF the MON <^ the MON = 0 the AND .; 
	the RUN; 
			
	/ *. 4, view data set frequency distribution * / 
	
	the PROC the SQL the NOPRINT; 
		the SELECT NAME the INTO: NLIST SEPARATED BY '' the FROM temp_t1; / * list of variables * / 
		the SELECT the tYPE the INTO: the TLIST SEPARATED BY '' the FROM temp_t1; / * variable type * / 
	
	% LET LVARNAME = IDENTITEY_TYPE BUSINESS_ORG_TYPE BUSINESS_TYPE PAYBACK_PERSON_TYPE CLASS5_STATE CURRENCY PAYMENT_STAUTS; / * Appendix variables * / 
	% LET LA = A1 A18 the A20 A44 A58 A32 A33; / * variable corresponds Appendix * / 
	% LET LA_LEN =% SYSFUNC (COUNTW (& LVARNAME).); 

	
	/ * calculate character variable length * / 
	the DATA temp_t2; 
		the SET & A.OUTPUTDATA(DROP=);
		 
		% the DO the I =. 1% the TO & NL .; 
			% LET Nl =% SCAN (& NLIST, & the I..); 
			% LET Tl = % SCAN (. & the TLIST, & the I.); 
			% the IF & Tl = 2% THEN% the DO; 
				& N1._len = the LENGTH (& Nl.); 
			% the END; 
		% the END; 
		
	the RUN; 
	
	
	% the DO the I =. 1% the TO & NL .; 
		% LET Nl =% SCAN (. & NLIST, & the I.); 
		% LET Tl =% SCAN; (& the TLIST, & the I..) 
		% the IF & Tl =. 1% THEN% the DO; / * numeric - check statistic * / 
			
			the PROC the SUMMARY the DATA = A. &OUTPUTDATA N NMISS MAX MIN ;
				& Nl on VAR; 
				the OUTPUT OUT = & Nl .; XLS. 
			The RUN; 
			
 			% the END; 
			
		%% the ELSE the DO; / * char - checking variable values and the variable values of the first two length * / 
			
			the PROC the FREQ the DATA = temp_t2; 
				. & TABLES Nl / MISSING OUT XLS & Nl .; =. 
				% M_APPENDIX_FORMAT (& Nl.); 
			the RUN; 
			
			the PROC the FREQ the DATA = temp_t2 the NOPRINT; 
				TABLES & N1._len / MISSING OUT = XLS & N1._len;. 
			the RUN; 
			
		% the END; 
	% the END; 
	
	
% MEND; 

% the CHECK;

  

Guess you like

Origin www.cnblogs.com/wdkshy/p/12455635.html