BookmarkSubscribeRSS Feed
ssas
Calcite | Level 5
Hi i need some help to find how to subtract with in the variable. here is the sample data

name x1 x2 x3
wk1 15 35 18
wk2 36 48 29
wk3 47 56 68
wk4 47 58 91
wk5 56 79 125
wk6 84 96 175
.
.
.
.


i would like to get the out like in the a1 ( wk2.x1-wk1.x1...) a2 ( wk2.x2-wk1.x2) a3 ( wk2.x3-wk1.x3)


name x1 x2 x3 a1 a2 a3
wk1 15 35 18 15 35 18
wk2 36 48 29 21(36-15) 13 (48-35) 11(29-18)
wk3 47 56 68 16 (47-36) 8 (56-48) 39 (68-29)
wk4 47 58 91 0 (47-47) 2 (58-56) 23 (91-68)
wk5 56 79 125
wk6 84 96 175
.
.
.
.



Thanks in-advance
sams
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Investigate using the DATA step and the LAG function, along with a sorted file and the BY statement so you can test IF FIRST.NAME THEN DO; END; in your DATA step and doing the subtraction correctly on all but the first observation in a BY group.


Scott Barry
SBBWorks, Inc.
ssas
Calcite | Level 5
Hi SBB,
Thanks for your help. I found the answer. I just used the dif function.

data cctest1;
set cctest;
tix06=dif(tix_sold_in_06);
tix07=dif(tix_sold_in_07);
tix08=dif(tix_sold_in_08);
if tix06 eq . then tix06=tix_sold_in_06;
if tix07 eq . then tix07=tix_sold_in_07;
if tix08 eq . then tix08=tix_sold_in_08;
run;

Thanks for your thought

sams

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1928 views
  • 0 likes
  • 2 in conversation