Hi, I am soon taking the Advanced Programmer exam but am stuck on one of the sample questions:
Write a SAS program that will:
• Create output data set work.ACT01 using sashelp.pricedata as input.
• Use an array to increase the values of the price1 through price17 variables by 10%.
Arrays and do loops would be used in the program.
I keep getting the subscript out of range error with this attempt:
data work.ACT01;
set sashelp.pricedata;
array original {17} price1-price17;
do i=1 - 17;
original{i} = original{i}*1.1;
end;
run;
do i = 1 to 17;
The - would be taken as subtraction. So Do i= -16 would be the first value of i and your array is not defined to have negative indices.
If you don't believe me place a PUT i; statement inside the do loop.
do i = 1 to 17;
The - would be taken as subtraction. So Do i= -16 would be the first value of i and your array is not defined to have negative indices.
If you don't believe me place a PUT i; statement inside the do loop.
data test;
set sashelp.pricedata;
array oldprice[17] price1-price17;
array newprice[17] price1-price17;
do i=1 to 17;
newprice[i]=oldprice[i]*1.1;
end;
drop i;
run;
Hi, below is my solution. I hope it helps.
DATA work.ACT01 (drop=i);
SET sashelp.pricedata end=lastrow;
ARRAY prc[17] price1-price17;
ARRAY prc_incr[17] ;
do i=1 to 17;
prc_incr[i] = prc[i]*1.1;
end;
run;
#You can do a proc print to check the first 10 observations.
proc print data=work.ACT01 (obs=10); run;
When answering ambiguous questions on exams it is best to add text that clarifies how you have interpreted the question.
Your interpretations seems to be that you want to create a new array of variables to hold the increased values.
Another valid interpretation is that they want you to update the existing variables' values.
* Assuming the request is to update the existing variables ;
DATA work.ACT01 ;
SET sashelp.pricedata ;
ARRAY price[17] ;
do i=1 to 17;
price[i] = price[i]*1.1;
end;
drop i;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.