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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

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.

ballardw
Super User

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;

jawon
Fluorite | Level 6

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 Smiley Happy

art297
Opal | Level 21

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.

art297
Opal | Level 21

I would suggest that you provide an example of what you really want to accomplish.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3158 views
  • 0 likes
  • 4 in conversation