DATA Step, Macro, Functions and more

Export Results to Excel

Reply
New User
Posts: 1

Export Results to Excel

I am a very new SAS university edition user, I have a huge table (20 columns, 4 million rows) and I want to filter the table according to one column (say all the values in column 8 should be equal to 334) and then sort the third column Ascendingly.

 

I can filter and sort the columns by right click on each column and get the results, but I do not know how can I get the table in excel.

Appreciate your help. 

 

This is the code:

 

PROC SQL;
CREATE TABLE WORK.query AS
SELECT SHIPMT_ID , ORIG_STATE , ORIG_MA , ORIG_CFS_AREA , DEST_STATE , DEST_MA , DEST_CFS_AREA , NAICS , QUARTER , SCTG , 'MODE'n , SHIPMT_VALUE , SHIPMT_WGHT , SHIPMT_DIST_GC , SHIPMT_DIST_ROUTED , TEMP_CNTL_YN , EXPORT_YN , EXPORT_CNTRY , HAZMAT , WGT_FACTOR FROM _TEMP0.cfs_2012_pumf WHERE NAICS like '%334%';
RUN;
QUIT;

PROC DATASETS NOLIST NODETAILS;
CONTENTS DATA=WORK.query OUT=WORK.details;
RUN;

PROC PRINT DATA=WORK.details;
RUN;

Super User
Posts: 24,010

Re: Export Results to Excel

Posted in reply to raha_tiny

Try a PROC EXPORT. 

 

You can also right click a Table in Libraries and select Export and export the data to your myfolders. 

 

 

 

 

Super User
Super User
Posts: 8,279

Re: Export Results to Excel

Posted in reply to raha_tiny

Which dataset do you want in EXCEL?  Your codes is creating a dataset named QUERY and then using PROC CONTENTS to create another dataset named DETAILS which you then print.

 

You can use ODS EXCEL to direct the PROC PRINT to an XLSX file.  So you could create a file named "myfile.xlsx" with something like this.

ods excel file='/folders/myfolders/myfile.xlsx';
proc print data=details;
run;
ods excel close;

 Or you could just copy the data instead of using PROC PRINT.

libname out '/folders/myfolders/myfile.xlsx';
proc copy inlib=work outlib=out;
  select details ;
run;
libname out close;
Ask a Question
Discussion stats
  • 2 replies
  • 1451 views
  • 0 likes
  • 3 in conversation