BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
StaticFX
Obsidian | Level 7

Currently I am using:

 

ODS CSV FILE="DISP_PRE1882.csv" TYPE=csvall PATH="/home/xxxx";

PROC PRINT DATA=COMBINED3;

RUN;

ODS CSV close;

 

wondering if there is a faster way to do this? The Dataset has amost 1 million rows and it can take a while...

Thanks!!

-Geoff

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Proc export data=combined

    outfile="DISP_PRE1882.csv"   /* second = character removed*/

    dbms=CSV

    replace

    ;

run;

 

If you want the variable labels instead of the names add LABEL before the  ; on the proc statement.

 

I do recommend always using a fully qualified path instead of just the out file name as the folder it ends up in may be problematic for some uses.

View solution in original post

7 REPLIES 7
ballardw
Super User

Proc export data=combined

    outfile="DISP_PRE1882.csv"   /* second = character removed*/

    dbms=CSV

    replace

    ;

run;

 

If you want the variable labels instead of the names add LABEL before the  ; on the proc statement.

 

I do recommend always using a fully qualified path instead of just the out file name as the folder it ends up in may be problematic for some uses.

StaticFX
Obsidian | Level 7

Ok, so I add the full path in the outfile? 

and why is there 2 ==?

 

 

Reeza
Super User

@StaticFX its a typo, a single = is fine. 

StaticFX
Obsidian | Level 7

Good lord its like night and day! this took 11.9 seconds to write 1.02m records to the file! Plus it was 27mb smaller... Thanks so much!

I havent tried the others to compare, but no need now lol

 

Tom
Super User Tom
Super User

You also might try writing directly to a compressed file and see if that makes it faster.  The computer will probably spend more CPU cycles compressing the file, but much less time will be spend waiting for the data to be written to the disk.

You could use the ZIP filename engine. And if you have at least SAS 9.4 M5 release you can use GZIP format which should be a little faster as it does not have the overhead of multiple file archives like ZIP format.

%let path=%sysfunc(pathname(work));

filename csv "&path/class.txt";
proc export data=sashelp.class file=csv dbms=csv ; run;

filename csvgz zip "&path/class.txt.gz" gzip ;
proc export data=sashelp.class file=csvgz dbms=csv ; run;

filename csvzip zip "&path/class.zip" member='class.txt' ;
proc export data=sashelp.class file=csvzip dbms=csv ; run;
Tom
Super User Tom
Super User

Just use a data step.

data _null_ ;
  file "/home/xxxx/DISP_PRE1882.csv" dsd ;
  set COMBINED3;
  put (_all_) (+0);
run;

If you need to add a header row you can generate that first and then use the MOD option on the FILE statement in the data step above.

proc transpose data=COMBINED3(obs=0) out=names;
  var _all_;
run;
data _null_ ;
  file "/home/xxxx/DISP_PRE1882.csv" dsd ;
  set names end=eof;
  put _name_ @ ;
  if eof then put;
run;

 

Ksharp
Super User
Or Check MACRO %ds2csv()

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!

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
  • 7 replies
  • 13904 views
  • 6 likes
  • 5 in conversation