Dataset FILES_TO_PROCESS looks like this:
FILE_NUM
401
412
439
I'd like to create a macro program with a do loop where "i" takes on those values. My workaround is something like this...
proc sql;
select min(FILE_NUM) into :min_num
from FILES_TO_PROCESS
;
select max(FILE_NUM) into :max_num
from FILES_TO_PROCESS
;
quit;
%macro start_processing;
%do i = &min_num %to &max_num;
<yadda yadda yadda>
%mend;
But of course that will cause the do loop to iterate 39 times, as opposed to just the 3 needed.
Help!
Here's a quick example of taking one field from multiple rows of data file and stepping through them. Look in the log for the output.
%macro dummy;
proc sql noprint;
select make into :cars separated by ' '
from sasuser.carpref
;
quit;
%do i = 1 %to &sqlobs ;
%let name= %scan(&cars,&i);
%put Do something with &name; /* this is where your useful code would go*/
%end;
%mend;
%dummy;
Where is the files to process coming from, a SAS library or a windows or unix directory.
If they all have the same extension you can use a wildcard to process everything in one directory at once...depending on what you're doing of course.
Here's a quick example of taking one field from multiple rows of data file and stepping through them. Look in the log for the output.
%macro dummy;
proc sql noprint;
select make into :cars separated by ' '
from sasuser.carpref
;
quit;
%do i = 1 %to &sqlobs ;
%let name= %scan(&cars,&i);
%put Do something with &name; /* this is where your useful code would go*/
%end;
%mend;
%dummy;
Thank you ballardw, that works like a charm! Apologies to the others for not providing the full details, but I guess I got lucky that ballardw was on the same wavelength
Glad to hear that you received an answer that you found useful. However, in the future, the more details you can provide upfront, the more quickly and assuredly others can try to provide a useful response.
I would suggest that you provide an example of what you really want to accomplish.
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.