Home Forums Main Forums SAS Forum If 0 then set… what’s the use of it?

  • If 0 then set… what’s the use of it?

     Datura updated 3 years, 2 months ago 1 Member · 1 Post
  • Datura

    Member
    February 2, 2021 at 6:37 pm

    Sometimes you may see people use “if 0 then set …” like below, what the hell it is doing?

    data _null_;
    if 0 then set MYDATA.TEST NOBS=Num;
    call symput("Loops", Num);
    run;

    ” If 0 then ” prevents the SET statement from executing, i.e. reading observations and loading the real data. It is used to assign the value of NOBS to Num only. However, the data step NOBS variable is set at compile time when data set meta data info is read, hence available to the SYMPUT statement.

    Note:
    SAS evaluates the expression in an IF-THEN statement to produce a result that is either non-zero, zero, or missing. A non-zero and non-missing result causes the expression to be true; a result of zero or missing causes the expression to be false.

    This is a neat trick in real work!

Log in to reply.

Original Post
0 of 0 posts June 2018
Now