lundi 26 octobre 2015

Output ZIP dataset

I am looking for some help with creating a macro utilizing an array as well as DO and IF statements for subsetting. Within my macro statement I am trying to look across columns for variables, and if the variable has a specific diagnosis code to then create a new variable and label as 1, and if not label all others as 0 to create one new data set based on that new variable, sort that data set, and append it to other data sets (because the input data sets are broken down quarterly), thus creating one final data set that I can then export (preferably as a newly created ZIP file to keep storage space down). I am using SAS 9.4/ Enterprise Guide 7.1.

Code:

OPTIONS MERROR SERROR SOURCE MLOGIC SYMBOLGEN MINOPERATOR OBS=MAX;
%MACRO DIAGXX(a,b);
DATA NEW;
    SET x.&a(KEEP= PATID DIAG1-DIAG5);
    ARRAY &b{5} $ DIAG1-DIAG5;
    DO I = 1 TO 5;
        IF &b{I} IN ("1630" "1631" "1638" "1639") THEN MESO = 1; 
        ELSE MESO = 0;
    END;
    DROP I;
RUN;

PROC SORT DATA=NEW NODUPKEY;
    BY PATID;
    WHERE MESO=1;
RUN;

PROC APPEND BASE=ALLDATA1 DATA=NEW FORCE;
RUN; 

PROC EXPORT
        DATA=ALLDATA1
        OUTFILE= "C:\x\x\DIAGNOSIS EXPORT\MACRO DIAGXX MESO.CSV"
        REPLACE
        DBMS=CSV;
RUN;
%MEND DIAGXX;

%DIAGXX(Q1,MESTH);
%DIAGXX(Q2,MESTH);

Aucun commentaire:

Enregistrer un commentaire