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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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