In reply to Yash.

Hello,

To accomplish the task you mentioned you just need to add the hospital name as another parameter. I have modified the code, see below:

data hospitals;
input name $ hospital_id $ quarter number_of_patients;
datalines;
St.Luke A100 1 125
St.Luke A100 2 115
St.Luke A100 3 130
Rex A200 1 200
Rex A200 2 195
Rex A200 3 180
Rex A200 4 190
;

/* this macro uses PROC EXPORT to write data to a .csv file */

%macro mymacro(hosp_id,name);

proc export data=hospitals(where=(hospital_id="&hosp_id"))
outfile="c:\hospitals\&hosp_id._&name..csv"
dbms=csv
replace;
run;

%mend;

data _null_;
set hospitals;
by hospital_id;

/* this logic allows us to call the MYMACRO macro
each time the value of HOSPITAL_ID changes */

if first.hospital_id then do;
call execute(cats('%mymacro(',hospital_id,',',name,');'));
end;
run;