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

Hi All,

I need to subtract 200 variables(heat, speed, weight......) for time points(7-0, 15-0) for 40 subjects(jack, ben, carol....). What would be the best way to do that?

My data set looks like this

subjectstimeheatspeedweight
jack06020179
jack75025179
jack156023175
ben 04830160
ben 76232159
ben 155729156
carol03930136
carol75027136
carol156324134

I want table like this

subjectstimeheatspeedweight
jack06020179
jack75025179
jack156023175
ben 04830160
ben 76232159
ben 155729156
carol03930136
carol75027136
carol156324134
jack_7/0-10-50
jack_15/00-3-4
ben _7/0142-1
ben _15/09-1-4
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Here is a simple way, using proc transpose twice:

proc transpose data=have out=t1;

by subject notsorted;

id time;

var heat -- weight;

run;

data t2;

set t1;

_7_0 = _7 - _0;

_15_0 = _15 - _0;

run;

proc transpose data=t2 out=want name=time;

by subject notsorted;

id _name_;

var _7_0 _15_0;

run;

PG

PG

View solution in original post

5 REPLIES 5
ballardw
Super User

This line:

jack_7/0-10-50

has 2nd-first  for heat and weigh but first-2nd for speed. Is that correct? You say you have 200 variables are they all order dependent or did you actually mean to subtract the first from the second in all cases?

Also is time currently numeric? If so it will have to change to character to accommodate values like _7/0.

esita
Calcite | Level 5

Yes, that is correct!

Yes, subtract first from the second and third. so subtract time 0 from time 7 and time 15 for all .

No time is character.

Thanks!

PGStats
Opal | Level 21

Here is a simple way, using proc transpose twice:

proc transpose data=have out=t1;

by subject notsorted;

id time;

var heat -- weight;

run;

data t2;

set t1;

_7_0 = _7 - _0;

_15_0 = _15 - _0;

run;

proc transpose data=t2 out=want name=time;

by subject notsorted;

id _name_;

var _7_0 _15_0;

run;

PG

PG
Ksharp
Super User

If your table was big .

data have;
input subject $     time     heat     speed     weight ;
cards;
jack     0     60     20     179
jack     7     50     25     179
jack     15     60     23     175
ben     0     48     30     160
ben     7     62     32     159
ben     15     57     29     156
carol     0     39     30     136
carol     7     50     27     136
carol     15     63     24     134
;
run;
data want;
 set have;
 by subject notsorted;
 length char_time $ 10;
 array x{*} _time var1-var800;
 array y{*} time  heat -- weight ;
 retain  _time var1-var800;
 if first.subject then do;
  do i=1 to dim(y);
   x{i}=y{i};
  end;
 end;
 else do;
  char_time=catx('/',time,_time);
  do i=2 to dim(y);
   y{i}=y{i}-x{i};
  end;
  output;
 end;
 drop i time _time  var:;
run;


Xia Keshan

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1797 views
  • 0 likes
  • 4 in conversation