• Print  |
  • Feedback  |

Training & Bookstore

Question from the Field

Question: How can you create a program to spot all occurrences of a value across many different columns in a data set?

Answer: There is a VNAME function that will return the name of the variable associated with a given array reference. Here's a program that does what you ask. Check out the final DATA step; the first two steps are just generating some sample data:
/*Make up some dummy data*/

data data;
    do obs=1 to 20;
    do varnum=1 to 10;
        varname='NumVar'!!left(varnum);
        value=round(ranuni(123)*10);
    output;
    end;
    end;
run;

proc transpose data=data out=testdata(drop=obs _name_);
    by obs;
    var value;
    id varname;
run;

data testdata;
    set testdata;
    length refused $ 200;
    array numvar {10};
    do index=1 to 10;
if numvar{index}=7 then refused=catx(' ',refused,vname(numvar{index}));
    end;
run;

proc print data=testdata; 
run;


View question archives.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.