Solved
Regular Learner
Posts: 1

# pulling out values from transposed data

Hi,

I have data like this.

id  day1 day2 day3 day4 day5 day6 day7 day8 day9 day10..

1      .       .        3       .        .       6       .         8       .        .

2      .       .        .        4      .        .       7         .        .        10

3     1      2       .        .       .        .      .          .        .         .

4     1      .        3        .       .       .        7         .        .         .

5     .       .        .         .       5      .        .          .        .         .

I want to pull out values not missing.. like this,

id   var1   var2    var3    var4    var5 ...

1      3       6         8          .          .

2      4       7         10        .          .

3      1       2          .        .           .

4      1       3         7        .            .

5      5       .          .         .            .

day variables are over 2000, observations are over 500000.

Can anyone help me?

Thanks!

Accepted Solutions
Solution
‎04-19-2016 05:21 AM
Super User
Posts: 9,599

## Re: pulling out values from transposed data

```proc transpose data=have out=want;
by id;
var day:;
run;

data want;
set want;
where _result_ ne .;
run;

/* And then if you have to transpose again */
proc transpose data=want out=t_want;
by id;
var _result_;
run;```

You will find 99% of programming tasks are easier with normalised data.  The only time to use transposed data is in an actual repotr file - i.e. at the time of proc report.  At any other programming moment, by group processing is far simpler to code, and maintain, and uses less resources.  The alternative is a messy, harder to maintain array type coding (which of course you woul need to do again and again for each step):

```data want;
set have;
array day{10};
array var{10} 8;
j=1;
do i=1 to 10;
if day{i} ne . then do;
var{j}=day{i};
j=j+1;
end;
end;
run;
```

Now the code doesn't look too bad for that one check, but you need to know how many var values are used, and how many day values are up front etc.  Makes code harder to maintain.

All Replies
Solution
‎04-19-2016 05:21 AM
Super User
Posts: 9,599

## Re: pulling out values from transposed data

```proc transpose data=have out=want;
by id;
var day:;
run;

data want;
set want;
where _result_ ne .;
run;

/* And then if you have to transpose again */
proc transpose data=want out=t_want;
by id;
var _result_;
run;```

You will find 99% of programming tasks are easier with normalised data.  The only time to use transposed data is in an actual repotr file - i.e. at the time of proc report.  At any other programming moment, by group processing is far simpler to code, and maintain, and uses less resources.  The alternative is a messy, harder to maintain array type coding (which of course you woul need to do again and again for each step):

```data want;
set have;
array day{10};
array var{10} 8;
j=1;
do i=1 to 10;
if day{i} ne . then do;
var{j}=day{i};
j=j+1;
end;
end;
run;
```

Now the code doesn't look too bad for that one check, but you need to know how many var values are used, and how many day values are up front etc.  Makes code harder to maintain.

🔒 This topic is solved and locked.