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
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;
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;
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);
Thank you so much! I've been at it for the past 3 hours and was about ready to pull my hair out!
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 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.