View Gives Different (Better?) Result

Discussion in 'SAS (Statistical Analysis Software)' started by Guest, Jul 18, 2005.

  1. Guest

    Guest Guest

    This is a little strange.

    data class;
    set sashelp.class;
    keep name nosuch;
    retain nosuch;
    run;

    As expected, the log shows:

    NOTE: Variable nosuch is uninitialized.

    then

    WARNING: The variable nosuch in the DROP, KEEP, or
    RENAME list has never been referenced.

    NOTE: The data set WORK.CLASS has 19 observations and 1 variables.

    *not* as expected. Usually, variables are included in the PDV even if not
    initialized. Not in this situation.

    Moreover, a view behaves differently. Make it:

    data classview / view=classview;
    set sashelp.class;
    keep name nosuch;
    retain nosuch;
    run;

    to define the view, then

    data classfromview;
    set classview;
    run;

    to evaluate it, and the log shows:

    NOTE: Variable nosuch is uninitialized.

    and

    NOTE: The data set WORK.CLASSFROMVIEW has 19 observations
    and 2 variables.

    So in this case the uninitialized variable *is* created.

    So there are two questions:

    1. Why is the variable NOSUCH not present in the first data set created?

    2. Why does a view behave differently in this regard?
     
    Guest, Jul 18, 2005
    #1
    1. Advertisements

  2. Case 1.
    A retained variable that is neither assigned a value nor type&length (by
    direct statement {such as VAR=..., retain VAR value, LENGTH, ATTRIB or array
    initialization} or indirect action {such as a SET or PUT})does not enter
    the PDV.
    [ I recall a thread on this a few years back. ]

    The compiler never encounters Nosuch in a situation wherein default
    attributes type/length are necessary to be known during data step
    compilation. This state means Nosuch does not enter the PDV.

    Case 2.

    The same data step, but as a view
    This one is perplexing.
    Nosuch takes default attributes of type numeric and length 8.


    Case 1 examples: statements indirectly cause compiler to enter Nosuch into
    PDV
    -----------------
    data class;
    set sashelp.class;
    keep name nosuch;
    retain nosuch;
    put nosuch=;
    run;
    -----------------
    data class;
    set sashelp.class;
    keep name nosuch;
    retain nosuch;
    a = addr (nosuch);
    run;
     
    Richard A. DeVenezia, Jul 18, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.