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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.