Calcite | Level 5

## What would be the command to break this data up from long to wide (array).

Hey guys, back again. I've been asking a lot of dumb questions but I've had a really crummy weekend and my professor absolutely loaded us down and I'm just trying to get through this one the last problem. I have this data that I need to convert from tall to wisde using an array. I have it mostly done out, but I can't figure out the last few commands, namely the first and last commands as well as the variable multiplication command in the third to last line that actually helps break up the data. If someone could kindly answer that would be amazing....

Data THIN;
Input ID \$ Time X @@;
Datalines;
001 1 10 001 2 12 001 3 15
004 1 17
003 1 14 003 2 18 003 3 22 003 4 28
002 1 18 004 2 28
;

Proc sort data= THIN;
by ID;
Run;

data Thin_Wide;
set THIN;
by ID;
retain X1-X4;
array Var[4] X1-X4;
if first.ID then do i=1 to 4;
var[i]=.;
end;
Var[X{i}]=X{i};
if last.ID;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: What would be the command to break this data up from long to wide (array).

Example data of start and end are much better than showing code that doesn't do what is required.

And since your code generates errors you should share the log of the data step throwing errors. How do I know your code throws errors: This bit

Var[X{i}]=X{i};

Is going to throw errors because you do not have an ARRAY named X defined.

Second, your X values are pretty much all larger than 10 and the array Var is only defined to have 4 elements.

I might guess that you actually intend to use TIME as the index for the Var array, not x{i} [which does not exist in any form]. But since you don't show what the result is supposed to be that is just a guess.

And why "array" if proc transpose does this?

2 REPLIES 2
Super User

## Re: What would be the command to break this data up from long to wide (array).

Example data of start and end are much better than showing code that doesn't do what is required.

And since your code generates errors you should share the log of the data step throwing errors. How do I know your code throws errors: This bit

Var[X{i}]=X{i};

Is going to throw errors because you do not have an ARRAY named X defined.

Second, your X values are pretty much all larger than 10 and the array Var is only defined to have 4 elements.

I might guess that you actually intend to use TIME as the index for the Var array, not x{i} [which does not exist in any form]. But since you don't show what the result is supposed to be that is just a guess.

And why "array" if proc transpose does this?

Calcite | Level 5

## Re: What would be the command to break this data up from long to wide (array).

Well, the purpose of our assignment is to use the array, its actually in the chapter question. Thank a bunch for pointing that out. I actually just neglected the time variable.......again its been one of those weekends. Thanks a bunch.
Discussion stats
• 2 replies
• 343 views
• 0 likes
• 2 in conversation