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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.