BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmj636
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

kmj636
Obsidian | Level 7

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?

Kurt_Bremser
Super User

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1492 views
  • 1 like
  • 2 in conversation