Solved
Contributor
Posts: 26

# Representation of column numbers

Dear all,

Today i came with another stupid question, That i am having problem with column representation and the dataset given bellow

Now I need to create another dataset with all these variables and an extra variable which is calculated from T1, T2, T3, T4, Lower. Consider T1 as 1, T2 as 2, T3 as 3, T4 as 4. nSuppose ” lower”  contains value 0.53 which is positioned at “T2” so the new variable will contains 2 and “lower “ is 1 then new variable contains 3 ……

For the above dataset the calculated result will be given in dataset bellow. Resulted variable spoted in green color.

Accepted Solutions
Solution
‎07-30-2016 07:19 AM
Super User
Posts: 10,020

## Re: Representation of column numbers

The more succinct code is :

### Code: Program

`data have;input t1-t4 low;cards;0 0.51 1 2 10 0.53 1 2.02 0.53;run;data want; set have; array x{*} t:;first=whichn(low,of x{*}); run;`

All Replies
Valued Guide
Posts: 860

## Re: Representation of column numbers

This is simple enough, I was trying to find a simpler solution using scan but didn't get there.  I'm hoping someone comes up with something more eligant in case this is a situation with a large dataset.

data have;

infile cards dsd dlm= ' ';

input c1 c2 t1 t2 t3 t4 lower;

cards;

.7514 10.215 0 .51 1 2 1

1.08674 9.123 0 .53 1 2.02 .53

1.2134 10.324 0 .5 1 2 2

.23421 12.1234 0 .5 1.03 2 1.03

;

run;

data want;

set have;

if lower = t1 then first = 1;

else if lower = t2 then first = 2;

else if lower = t3 then first = 3;

else if lower = t4 then first = 4;

run;

Super User
Posts: 10,020

## Re: Representation of column numbers

### Code: Program

`data have;input t1-t4 low;cards;0 0.51 1 2 10 0.53 1 2.02 0.53;run;data want; set have; array x{*} t1-t4; do i=1 to dim(x);  if x{i}=low then do;first=i;leave;end; end; drop i; run;`

Valued Guide
Posts: 860

## Re: Representation of column numbers

Xia,

I think I've seen this but do not remember the solution, if you do not know how many t values there are is there a way to say array x{*} t1-t 'nth; ?

Thanks,

Solution
‎07-30-2016 07:19 AM
Super User
Posts: 10,020

## Re: Representation of column numbers

The more succinct code is :

### Code: Program

`data have;input t1-t4 low;cards;0 0.51 1 2 10 0.53 1 2.02 0.53;run;data want; set have; array x{*} t:;first=whichn(low,of x{*}); run;`
Super User
Posts: 7,942

## Re: Representation of column numbers

Hi,

data want;

set have;

array t{4};

do i=1 to 4;

if t{i} <= lower and first=. then first=i;

end;

run;

🔒 This topic is solved and locked.