Hi,
is it possible for me to create an array calling say 150 variables (50 have similar prefix so three with Ax Bx Cx Yx ... Ap Bp Cp Yp... As Bs Cs Ys) and then make a macro within a do group? Then use that %let in the next data step?
Data work.question;
set ABCY;
array ques(*) A: B: C: Y: ;
do i=1 to dim(ques);
if ques(i) then do
%let county=coun(i);
end;
run;
Any help on this or suggested reading for this would be greatly appreciated. Thank you so much for your time!
Arrays are data step elements and therefore not accessible for macro code. The macro PREprocessor does its work before the data step is even compiled.
And even if you use the proper subroutine (call symput), it is a bad idea to store large amounts of values in macro variables (in about 100% of cases). Data is best kept in datasets.
It is quite easy to create dynamic code off datasets with call execute.
Arrays are data step elements and therefore not accessible for macro code. The macro PREprocessor does its work before the data step is even compiled.
And even if you use the proper subroutine (call symput), it is a bad idea to store large amounts of values in macro variables (in about 100% of cases). Data is best kept in datasets.
It is quite easy to create dynamic code off datasets with call execute.
So what I would really like to do is to pull three (of the same prefix) of the 150 into another dataset for processing. I do not want to have to enter each of the variables fifty times. Do you have a better suggestion for this processing?
Please post an example of your source dataset (see my footnotes for hints how to post example datasets), and what you expect to get out of it.
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.