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;
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?
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.