forked from lucieluyiliu/WRDS-SAS-UTILITIES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
#MISSING VALUE REPORT.SAS#
84 lines (71 loc) · 2.29 KB
/
#MISSING VALUE REPORT.SAS#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
LIBNAME AMA_V "/wrds/bvd/sasdata/ama_v";
%LET INDSN=AMA_V.COMPANY_V;
%MACRO CHK_MISSING(INDSN, OUTDSN);
%IF %LENGTH (&INDSN) = 0
%THEN %DO;
%GOTO ENDIT1;
%END;
%IF %LENGTH (&INDSN) = 0
%THEN %DO;
%GOTO ENDIT1;
%END;
PROC CONTENTS DATA=&INDSN OUT=__AC1__ NOPRINT;
RUN;
PROC SQL NOPRINT;
SELECT NAME INTO :_V_LIST_ SEPARATED BY '~' FROM __AC1__;
SELECT COUNT(*) INTO :_NUMOBS_ FROM __AC1__;
QUIT;
%PUT _V_LIST_ = &_V_LIST_;
%PUT _NUMOBS_ = &_NUMOBS_;
PROC SQL;
CREATE TABLE __AC2__ AS
SELECT
%LET __I__=1;
%DO %UNTIL(&__I__ > &_NUMOBS_);
%IF &__I__ = &_NUMOBS_ %THEN %DO;
NMISS(&SCAN(&_V_LIST_,&__I__,%STR(~))) AS %SCAN(&_V_LIST_,&__I__,%STR(~))
%END;
%ELSE %DO;
NMISS(&SCAN(&_V_LIST_,&__I__,%STR(~))) AS %SCAN(&_V_LIST_,&__I__,%STR(~))
%END;
FROM &INDSN;
QUIT;
PROC TRANSPOSE
DATA=__AC2__
OUT=__AC3__ (RENAME(COL1=MISS_COUNT))
NAME=VARS;
RUN;
PROC SQL;
CREATE TABLE __AC4__ AS
SELECT
A.VARNUM AS VARNUM LABEL = "#",
A.NAME AS NAME LABEL = "VARIABLE",
A.TYPE AS TYPE,
A.LENGTH AS LENGTH LABEL = "LEN",
A.FORMAT AS FORMAT LABEL="FORMAT",
A.LABEL AS LABEL="LABEL",
A.NOBS,
B.MISS_COUNT AS MISS_COUNT
FROM
__AC1__ AS A
LEFT JOIN
__AC3__ AS B
ON A.NAME EQ B.VARS
ORDER BY VARNUM;
QUIT;
DATA __AC5__;
SET __AC4__;
MISS_PCT = MISS_COUNT/NOBS;
FORMAT MISS_COUNT COMMA20.
MISS_PCT PERCENT8.3;
RUN;
DATA &OUTDSN;
FORMAT VARNUM NAME TYPE_;
SET __AC5__;
LENGTH TYPE_ $4;
IF TYPE EQ 1 THEN TYPE_="NUM";
ELSE IF TYPE EQ 2 THEN TYPE_="CHAR";
IF FORMAT1 NE 0 AND FORMATD NE 0 THEN DO;
FORMAT = STRIP(FORMAT)||STRIP(PUT(FORMAT1,3.))||"."||STRIP(PUT(FORMATD,3.));
END;
ELSE IF FORMAT1 NE 0 THEN FORMAT=