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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.