Ah...that's not my code 🙂
The loop counter is set incorrectly.
Whrn you declare an array with (1973:2011) the array needs to be indexed with those values.
Change the do line to
do I=1973 to 2011;
Definitely a use for arrays. What did you try?
Use anything other than IE/Edge and hit Reply not quick reply.
The only issue I could see possibly running into is if all variables aren't same type.
Array varin (*) var1-var25;
array varout(*) vout1-vout25;
If (condition) then do;
Do I=1 to dim(varin);
Varout(I)=varin(I);
End;
end;
Array 101 tutorial
Yeah. Post some data and output to explain your question. data table3; set table2 ; array year [1973:2011] yr1973-yr2011; array ayear [1973:2011] ayr1973-ayr2011; if AGE = 0 then do; do i=1 to dim(year); ayear[i]=year[i]; end; end; else ayr1973 = yr1973; run;
@Ksharp Does I=1 work as an index in your code?
The code works Please try it and post any errors or explain any issues with sample data.
Post your exact code please.
Ah...that's not my code 🙂
The loop counter is set incorrectly.
Whrn you declare an array with (1973:2011) the array needs to be indexed with those values.
Change the do line to
do I=1973 to 2011;
@RedMcCallen wrote:
data etn.table3;
set etn.table2;
by BEN_AGE;
array year [1973:2011] yr1973-yr2011;
array ayear [1973:2011] ayr1973-ayr2011;
if AGE = 0 then do;
do i = 1 to dim(year);
ayear[i]= year[i];
end;
end;
else
ayr1973 = yr1973;
run;
That code should have been generating array subscript out of range error messages.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.