BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi everyone,
I am not sure about the right forum but...

I have a problem problem and I would be thankful if somebody can solve this.

I have dataset like this...

DOCTOR PATIENT
Ann Mark
John Anton
Ann Jeff
Ann James
John Howard
William Cliff
. .
. .
. .

And I should export this dataset to different excel files by using keyvariable DOCTOR like this...

PROC EXPORT DATA=doctorset
OUTFILE="c:\data\Ann.xls" DBMS=EXCEL2000 REPLACE;

PROC EXPORT DATA=doctorset
OUTFILE="c:\data\William.xls" DBMS=EXCEL2000 REPLACE;

PROC EXPORT DATA=doctorset
OUTFILE="c:\data\John.xls" DBMS=EXCEL2000 REPLACE;

PROC EXPORT DATA=doctorset
OUTFILE="c:\data\xxxx.xls" DBMS=EXCEL2000 REPLACE;
run;

Can I use some kind of macro or something? The dataset is so large that I cannot use handjob...

Thank you for advance!
2 REPLIES 2
Chevell_sas
SAS Employee
You could use the below macro to do this. It creates a list of macro variables from the variable doctor and loops through the PROC EXPORT statements. The value of doctor is resolved in both the WHERE= data set option as well as the OUTFILE=option.

You might also want to take a look at the ExcelXP tagset which allows you to generate multiple worksheets based on the by value as well. See the below for more information on this.

http://support.sas.com/rnd/base/topics/odsmarkup/



Ex1.

data one;
input DOCTOR $ PATIENT $;
cards;
Ann Mark
John Anton
Ann Jeff
Ann James
John Howard
William Cliff
;
run;

/* Create a list of macro variables */

proc sql noprint;
select count(distinct doctor) into :last
from one;

select distinct(doctor) into: val1- :val%left(&last)
from one;
run;
quit;

%macro loopit;
%do i=1 %to &last;

PROC EXPORT DATA=one(where=(doctor="&&val&i"))
OUTFILE="c:\data\&&val&i" DBMS=EXCEL2000 REPLACE;

run;
%end;
%mend;
%loopit


Ex2.

data one;
input DOCTOR $ PATIENT $;
cards;
Ann Mark
John Anton
Ann Jeff
Ann James
John Howard
William Cliff
;
run;


proc sort data=one;
by doctor;
run;
ods tagsets.excelxp file="temp.xls";

proc print data=one;
by doctor;
run;

ods tagsets.excelxp close;
deleted_user
Not applicable
Thank you Chevell!
Message was edited by: IlariSAS at May 12, 2006 2:14 AM

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 669 views
  • 0 likes
  • 2 in conversation