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

I am attempting to convert the following code to using an ARRAY(s) instead of individual entries.

My Current code with individual entries is as follows:

Data WGTCHG(Drop=name dob marital race)DEMO(Keep=name dob marital race);

Set Wgt2.weights2;

CHANGEV2=wgt2-wgt1;

CHANGEV3=wgt3-wgt2;

CHANGEV4=wgt4-wgt3;

CHANGEV5=wgt5-wgt4;

CHANGEV6=wgt6-wgt5;

CHANGEV7=wgt7-wgt6;

CHANGEV8=wgt8-wgt7;

CHANGEV9=wgt9-wgt8;

CHANGEV10=wgt10-wgt9;

CHNAGEV11=wgt11-wgt10;

RUN;

I have been unsuccessful finding an example in these forums, UCLA and Stanford's SAS pages so any help would be greatly appreciated!

Thanks!

Scouter

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I'm assuming you have more code in your data step because you indicated two output data sets, but hopefully this helps:

Data  WGTCHG(Drop=name dob marital race) DEMO(Keep=name dob marital race);

Set Wgt2.weights2;

array change(2:11) changev2-changev11;

array wgt(1:11) wgt1-wgt11;

do i= 2 to 11;

change(i)=wgt(i)-wgt(i-1);

end;

RUN;

View solution in original post

3 REPLIES 3
Reeza
Super User

I'm assuming you have more code in your data step because you indicated two output data sets, but hopefully this helps:

Data  WGTCHG(Drop=name dob marital race) DEMO(Keep=name dob marital race);

Set Wgt2.weights2;

array change(2:11) changev2-changev11;

array wgt(1:11) wgt1-wgt11;

do i= 2 to 11;

change(i)=wgt(i)-wgt(i-1);

end;

RUN;

art297
Opal | Level 21

I had the same suggestion as Fareeza, but suggest using _n_ rather than i, or adding i do your drop variables. _n_ will automatically be dropped.  i.e.:

do _n_= 2 to 11;

change(_n_)=wgt(_n_)-wgt(_n_-1);

chris21baseball_hotmail_com
Calcite | Level 5

Thank you so much! I've been at it for the past 3 hours and was about ready to pull my hair out!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1584 views
  • 3 likes
  • 3 in conversation