mardi 7 août 2018

SAS not able to read observations

Backstory - I am working with a migration matrix for a summer school project, the idea is that you prevent non-performing loans from becoming performing again. So, I have written a little script to generate some code from an excel - the excel looks like this:

data book1;
input Row_status $ Col_status $ Bucket $ Restrict $;
datalines;

NPF PF "00" Yes
;
run;

Now, my dataset looks like this:

data matrix;
input Row_status $ Col_status $ Bucket $ flow;

NPF NP "00" 0.5
NPF NP "01" 1
;
run;

the script I use to run this is as follows:

data _null_;
    set book1;
    file Matrix;
    if upcase(compress(Restrict)) eq 'YES' then
    do;
        if _N_ eq 1
            then put 'if Row_Status eq strip("' Row_Status'") then
                      do;
                      if Col_Status eq strip("' Col_Status'") then
                      do;
                      if Bucket eq strip("' Bucket'") then do;
                      flow = 0;
                      end;
                      end;
                      end;';
        else put 'else if Row_Status eq strip("' Row_Status'") then
                      do;
                      if Col_Status eq strip("' Col_Status'") then
                      do;
                      if Bucket eq strip("' Bucket'") then do;
                      flow = 0;
                      end;
                      end;
                      end;';        
    end;

run;

the self generating script for the code works; however, when I try to use an %include matrix; during a datastep, it does not seem to be able to connect with the observation "00" any theoretical reasons behind this?

i.e. the variable bucket with "00" or "01" just does not connect.

If I hand type it myself and do not use strip or compress and just put bucket eq "00" then this works; however, it does not work if I use the self generating script I lose the autonomous feature then...

example of script that works when I write it:

if row_status = strip("NPF") then do;
    if col_status = strip("PF") then do;
        if bucket = "00" then do;
            Flow = 0;
        end;
    end;
end;

Aucun commentaire:

Enregistrer un commentaire