Writing Efficient Queries in SAS Using Proc sql with Teradata

后端 未结 5 522
[愿得一人]
[愿得一人] 2021-02-06 11:58

EDIT: Here is a more complete set of code that shows exactly what\'s going on per the answer below.

libname output \'/data/files/jeff\'
%let DateStart = \'01Jan         


        
5条回答
  •  长发绾君心
    2021-02-06 12:37

    If ID is unique and a single value, then you can try constructing a format.

    Create a dataset that looks like this:

    fmtname, start, label

    where fmtname is the same for all records, a legal format name (begins and ends with a letter, contains alphanumeric or _); start is the ID value; and label is a 1. Then add one row with the same value for fmtname, a blank start, a label of 0, and another variable, hlo='o' (for 'other'). Then import into proc format using the CNTLIN option, and you now have a 1/0 value conversion.

    Here's a brief example using SASHELP.CLASS. ID here is name, but it can be numeric or character - whichever is right for your use.

    data for_fmt;
    set sashelp.class;
    retain fmtname '$IDF'; *Format name is up to you.  Should have $ if ID is character, no $ if numeric;
    start=name; *this would be your ID variable - the look up;
    label='1';
    output;
    if _n_ = 1 then do;
      hlo='o';
      call missing(start);
      label='0';
      output;
    end;
    run;
    proc format cntlin=for_fmt;
    quit;
    

    Now instead of doing a join, you can do your query 'normally' but with an additional where clause of and put(id,$IDF.)='1'. This won't be optimized with an index or anything, but it may be faster than the join. (It may also not be faster - depends on how the SQL optimizer is working.)

提交回复
热议问题