BookmarkSubscribeRSS Feed
tparvaiz
Obsidian | Level 7

Hi,

 

I have 100+ different reports that create some sort of output.

 

I am looking for a way to run multiple reports as per demand (not as per schedule through EG scheduler) through a single SAS program (maybe, by selecting report paths or similar).

 

just to give you some background, our users might show up and would like us to run reports (anywhere between 5 to 20) immediately and in that case I would have to open each and everyone and without any modifications would have to just press run command. that consumes a lot of time.

 

please advise

 

16 REPLIES 16
Reeza
Super User

How are your jobs designed?

Is each report it's own eg project, it's own program?

 

If each is it's own SAS program put them in a SAS file with %include() and only run the ones as necessary.

If you want to be complicated you could create a file or macro that allows you to select this and then run as desired, usually if it's user driven, I'll add all reports to an excel sheet and then there's a yes/no flag they need to check - all are set at a default to no. 

 

Once they've selected their reports you can use that as an input to your process to automate the whole thing. This is what I'd do but I'm not in a server environment with automated tools for scheduling and such.

 

Also, look into Ordered Lists in EG to run tasks. http://support.sas.com/kb/26/177.html

tparvaiz
Obsidian | Level 7

Reeza,

 

every report is it's own project. I was thing you may suggest something like this

 

 

Run

c:\temp\proj1.sas;

c:\temp\proj2.sas;

c:\temp\proj3.sas;

 

 

please advise

 

Thanks again

SASKiwi
PROC Star

One way to do this is to set up a controlling program that runs all of the required reports. Here is how you could automate your report selections from a controlling program. Just change the list (Run_Pgm_List) at the top:

 

 

 %let Run_Pgm_List = proj1*proj2*proj3;
 %let app_saspgm_dir = C:\temp;

data _null_;
  length Run_Pgm_List $ 1024;
Run_Pgm_List = symget('Run_Pgm_List'); pgm_count = countw(Run_Pgm_List, '*'); if pgm_count ge 1 then do pgm_num = 1 to pgm_count; pgm_name = scan(Run_Pgm_List, pgm_num, '*'); call execute('%include "&app_saspgm_dir.\' !! strip(pgm_name) !! '.sas";'); end; end; run;

 

Reeza
Super User

Pretty much, but it's %include to allow the programs to run. 

 

 

tparvaiz
Obsidian | Level 7

where should I put %include

 

Thanks again

SASKiwi
PROC Star

@tparvaiz - in my code example above the %INCLUDE statements are generated automatically. All you have to do is supply the list of programs you want run.

tparvaiz
Obsidian | Level 7

Excellent!

 

can you please advise how to run multiples files if they are in a different folder, something like this

 

 

c:\temp Folder\ File 1.sas

c:\temp Folder 2\ File 2.sas

c:\temp Folder 3\ File 3.sas

 

thanks again for your assistance

Reeza
Super User

To run a program via %include the following is the structure:

 

%include 'C:\_localdata\temp.sas' \ LRECL=500;
SASKiwi
PROC Star
%let Run_Pgm_List = C:\temp1\proj1*C:\temp2\proj2*C:\temp3\proj3;

data _null_;
  length Run_Pgm_List $ 1024;
  Run_Pgm_List = symget('Run_Pgm_List');
  pgm_count = countw(Run_Pgm_List, '*');
  if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
    pgm_name = scan(Run_Pgm_List, pgm_num, '*');
    call execute('%include ' !! strip(pgm_name) !! '.sas";');
    end;
  end;
run;

 

 Just add the directories to the program list.

tparvaiz
Obsidian | Level 7

Hi Ran the following code and got the error message

 

--------------Here is the code that I ran --------------------------

%let Run_Pgm_List = 'M:\ABC Documents\ABC PROJECT\Mgmt. Reports\Reports in Progress\MYREPORTS\01_cnnDT\pgm\ReportNew - Auto;

data _null_;
length Run_Pgm_List $ 1024;
Run_Pgm_List = symget('Run_Pgm_List');
pgm_count = countw(Run_Pgm_List, '*');
if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
pgm_name = scan(Run_Pgm_List, pgm_num, '*');
call execute('%include ' !! strip(pgm_name) !! '.sas";');
end;
end;
run;

 

 

 

-----------------------Here is the log -------------------------

 

27 data _null_;
28 length Run_Pgm_List $ 1024;
29 Run_Pgm_List = symget('Run_Pgm_List');
30 pgm_count = countw(Run_Pgm_List, '*');
31 if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
32 pgm_name = scan(Run_Pgm_List, pgm_num, '*');
33 call execute('%include ' !! strip(pgm_name) !! '.sas";');
34 end;
35 end;
---
161
ERROR 161-185: No matching DO/SELECT statement.

36 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

 

SASKiwi
PROC Star

Sorry I accidently deleted a double quote. This should work better. Also don't put quotes into the Run_Pgm_List as in your version.

 

%let Run_Pgm_List = C:\temp1\proj1*C:\temp2\proj2*C:\temp3\proj3;

data _null_;
  length Run_Pgm_List $ 1024;
  Run_Pgm_List = symget('Run_Pgm_List');
  pgm_count = countw(Run_Pgm_List, '*');
  if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
    pgm_name = scan(Run_Pgm_List, pgm_num, '*');
    call execute('%include "' !! strip(pgm_name) !! '.sas";');
    end;
  end;
run;
tparvaiz
Obsidian | Level 7

still getting an error message

 

 

------------------code used -------------------

 

%let Run_Pgm_List = C:\Temp\test;

data _null_;
length Run_Pgm_List $ 1024;
Run_Pgm_List = symget('Run_Pgm_List');
pgm_count = countw(Run_Pgm_List, '*');
if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
pgm_name = scan(Run_Pgm_List, pgm_num, '*');
call execute('%include "' !! strip(pgm_name) !! '.sas";');
end;
end;
run;

 

-------------------log details ---------------------------

 

 

37 %let Run_Pgm_List = C:\Temp\test;
38
39 data _null_;
40 length Run_Pgm_List $ 1024;
41 Run_Pgm_List = symget('Run_Pgm_List');
42 pgm_count = countw(Run_Pgm_List, '*');
43 if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
44 pgm_name = scan(Run_Pgm_List, pgm_num, '*');
45 call execute('%include "' !! strip(pgm_name) !! '.sas";');
46 end;
47 end;
---
161
ERROR 161-185: No matching DO/SELECT statement.

48 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

Reeza
Super User

FORMAT YOUR CODE.

 

Tip: In EG you can highlight your code, hit CTRL+I and it will format it for you. 

Formatted you can very clearly see an extra end in your code.

 

%let Run_Pgm_List = C:\Temp\test;

data _null_;
	length Run_Pgm_List $ 1024;
	Run_Pgm_List = symget('Run_Pgm_List');
	pgm_count = countw(Run_Pgm_List, '*');

	if pgm_count ge 1 then
		do pgm_num = 1 to pgm_count;
			pgm_name = scan(Run_Pgm_List, pgm_num, '*');
			call execute('%include "' !! strip(pgm_name) !! '.sas";');
		end;
end; *<-----WHY DO YOU HAVE THIS;
run;
SASKiwi
PROC Star

@Reeza - thanks for spotting this. Thats the problem when you do a quick change to working code without testing!

 

%let Run_Pgm_List = C:\temp1\proj1*C:\temp2\proj2*C:\temp3\proj3;

data _null_;
  length Run_Pgm_List $ 1024;
  Run_Pgm_List = symget('Run_Pgm_List');
  pgm_count = countw(Run_Pgm_List, '*');
  if pgm_count ge 1 then do pgm_num = 1 to pgm_count;
    pgm_name = scan(Run_Pgm_List, pgm_num, '*');
    call execute('%include "' !! strip(pgm_name) !! '.sas";');
  end;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 16 replies
  • 1176 views
  • 1 like
  • 3 in conversation