BookmarkSubscribeRSS Feed
ablack
Calcite | Level 5

Hi. So I'm working with a file that contains hierarchical student level data, with one row per week. I want to export my data to excel. Ideally I would create one excel file per teacher, and one tab per student, data for each week presented on each row. I can easily sort by teacher and student, then do a proc print, by student. I get exactly what i need in SAS. I just can't figure out how to get those tables into multiple tabs in excel. And thoughts? I'm thinknig I need to use ODS, or soem sore of do loop to create mulltiple small data sets. BUt I'm hoping that there is a SAS feature I'm not familiar with that will simply export my proc print output.

 

3 REPLIES 3
Reeza
Super User

You're correct. ODS is probably your best bet. Depending on your version it may be ODS EXCEL or TAGSETS.EXCELXP


Look at the Data Driven workbook examples here.

https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html

 

If you want multiple files unfortunately you need a macro. Develop your base code first - ie get it working for ONE teacher using a WHERE filter on your proc prints and then post the code and we can help make it a macro.

 

 

 

 

Ksharp
Super User

Yes. Some skeleton code could like:

 

options nobyline;

ods excel options(sheet_interval='bygroup' , sheet_name='#byval1');

proc report data=class(where=(teacher='Arthur')) nowd;

by student;

....

ablack
Calcite | Level 5

Thank you! Here's the code I am using and it works beautifully. All is need is one proc print per teacher.

 

proc sort data=data.SDR_CUMULATIVE;

BY school fa name week;

 

ods listing close;

ods tagsets.ExcelXP path='U:\Data Team\2 Dashboards\1 Weekly\FY 17\reports' file='DA_Medina.xml'

style = daisy;

 

* Create a separate worksheet for each of Medina's Students;

proc print data=data.SDR_CUMULATIVE noobs label split='*';

where SCHOOL = 'DA' and FA = 'Medina';

by NAME;

var FA name week ENROLL_DT END_DT SCHOOLDAYS DAYS_PRESENT DAYS_ABSENT ATTRATE;

run; quit;

 

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
  • 3 replies
  • 12552 views
  • 0 likes
  • 3 in conversation