Help using Base SAS procedures

Using a range of variables in an "IF" statement

Occasional Contributor
Posts: 8

Using a range of variables in an "IF" statement

Hi all,

I am trying to create indicator variables, based on information in other variables in my table.  I have a data set in wide format (which I created from long) that has subject data at many (up to 700) different timepoints.  Basically, if ANY of those time points have a specific value, I'd like to create an indicator.  For example, if any of T1-T100 = 1, then I want INDICATOR=1.

Can I have SAS specify a range of variable to check in my IF statement?  I know I can us multiple "or" statements, but this is not practical, given the large number of time points.

Also, I considered writing it into my array when I converted from long to wide format, but this did not seem to work and I did not see documentation on this particular issue.

This is what I tried..

data wide (keep=id T1-T&mm var1-var&mm);

array T(&mm);

array var(&mm);

do j = 1 by 1 until (;

set data1;

by id;

T(j) = Time;

var(j) = score;

if var(j) = 20 then HIGH = 1; else HIGH=0;


Thanks for your help!


Respected Advisor
Posts: 3,777

Re: Using a range of variables in an "IF" statement

I think WHICHN will be helpful.

has1 = whichN(1,of T1-T100);

if has1 is greater than 1 then the range contains a least 1 variable with the target.

Occasional Contributor
Posts: 8

Re: Using a range of variables in an "IF" statement

Thanks, data_null, this is helpful.  It will return the ordered number of the first variable it hits, correct?  So if my data row were to look like

T1 T2 T3 T4

8   9  10  7

has1 = whichN(9, of T1-T4)

would return has1=2

This could work, because then I would just need to add a line of code if has1 > 0 then has1=1. 



Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation