Hi everyone,
I have a dataset that I transposed and I want to do an if statement across multiple columns. I have attached a dummy version of the dataset (real once is a little more extensive but same concept). I have pasted my code below that I am trying to use but i get an error (pasted below). The column names in the array will be slightly different.
Any help is appreciated.
Thanks everyone
ERROR: Array subscript out of range at line 38 column 22.
data target;
set trans;
array pre {2} $8 m_202001 m_202002;
array post {1} $8 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;
do i=1 to dim(time_period);
if pre[i] = '' and post[i] = '' then target = 1;
else if pre[i] ne '' and post[i] = '' then target = 2;
else if pre[i] = '' and post[i] ne '' then target = 3;
else target = 4;
end;
run;
Your index, i, goes from 1 to 3 and it indexes arrays with 1 or 2 elements. As you see, that does not work.
Because of the errors, it's impossible to determine what you are trying to accomplish. Here's a step you can take to eliminate the errors. But whether it accomplishes the right thing or not ... that's impossible to tell. Perhaps it will:
The current array definitions:
array pre {2} $8 m_202001 m_202002;
array post {1} $8 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;
Legally, you could change it to:
array pre {3} $8 m_202001 m_202002 m_202002;
array post {3} $8 m_202003 m_202003 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.