BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FrustratedBio
Calcite | Level 5

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
ballardw
Super User

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?

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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?

 

FrustratedBio
Calcite | Level 5
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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 386 views
  • 0 likes
  • 2 in conversation