Hello, I would like just as many array variables in the ouput dataset as there are loops. If the loop only runs three times and creates x1, x2, and x3, I would like to just keep those three variables and not all five. Using a macro that is being created within the same data step does not work and I'm pretty sure I know why. Any suggestions? Thanks! data dummy; checker=3; array x[5] $100.; do i = 1 to 10 while (checker > 0); x = 1 + 2; checker = checker - 1; end; call symputx("i",i); keep x1 - x&i; run; Not sure if this code actually runs. I just recreated something similar to my problem. Regards Phil
Phil,
This can't be done in a single step. The DATA step must be 100% compiled, including resolution of all macro variables referenced, before it executes.
It is easily possible to do this in two steps. You could easily add a second DATA step:
data dummy;
set dummy (keep=x1-x&i);
run;
That means reading/writing the observations again of course.
Good luck.
Phil,
This can't be done in a single step. The DATA step must be 100% compiled, including resolution of all macro variables referenced, before it executes.
It is easily possible to do this in two steps. You could easily add a second DATA step:
data dummy;
set dummy (keep=x1-x&i);
run;
That means reading/writing the observations again of course.
Good luck.
Thank you for your response, Astounding. My goal was to do it all in one data step, but after all this is an easy solution and it works. Thanks!
Instead of a second datastep why not place the keep data set options in the first one: data dummy (keep=x1-x&i .....) ;
Wouldn't that cause the same problem, since the data step needs to compile completely before the macro can be referenced?
You are right, did not notice the logic in your example.
Often I see this with a the datastep being included knowing the counter already. I did my conclusion too fast.
I did not get your logic as you did not mentioning that with your question. It seem not to be on dataprocessing it is possible matrices.
Often that is more easier to solve in an other way. We are all often mindblocked by some previous successes
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.