DATA Step, Macro, Functions and more

A question about sas data export

Reply
Contributor ZZB
Contributor
Posts: 34

A question about sas data export

I run a sas program and want to save the final table in sas format. So I can use the sas file directly in the future. How to save this table in sas format?

If I cannot save it in sas format, I can export this table into a CSV file. But I encounter a problem in the CSV file. For example,


SAS Fomat               CSV

CUSIP                     CUSIP

000888999                888999

00088E104               8.8E+105

....                            ....

Then I import the CSV file into sas and cannot the result in the original SAS format. How to solve this problem? Thanks



Super Contributor
Posts: 336

Re: A question about sas data export

If your final table is a SAS dataset you could create a permanent SAS-library (in case you are using the Enterprise Guide, there is an export button).

If your final table is the output of a procedure you could use the Output Delivery System-Output to get the procedure result and store it (in a library).

Contributor ZZB
Contributor
Posts: 34

Re: A question about sas data export

I use sas 9.3 Not the Enterprise version. How to export the SAS dataset by creating a permanent SAS-library?

The enterprise version only displays the first 50 tables but the final table is beyond 50th.

Super Contributor
Posts: 336

Re: A question about sas data export

You can use either in Enterprise Guide: Click on your data file > Enterprise menu: "File" > "Export" > "Export <Filename>" > choose a directory and make sure that the "Files of type" is "Sas data file ..".

Or use code. This example "copies" the work file "A" to a folder:

* this is a work-file (non-permanent);
Data Have;
  Do i=1 To 10 ; Output; End;
Run;

Libname MyLib "C:\Users\USERNAME\Desktop\SAS folder"; * check the path and make sure the folder exists - create manually :smileyalert: if necessary;

Data Have; * "copy" the work file to the library;
  Set MyLib.Have;
Run;

.. hope it helps :-)

Super User
Posts: 6,927

Re: A question about sas data export

I'd rather do

Data MyLib.Have;
  Set Have;
Run;


Smiley Happy

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 336

Re: A question about sas data export


You're right, that was silly.

Data MyLib.Have;

  Set Have;

Run;

it is.

Super User
Posts: 6,927

Re: A question about sas data export

Look for the step that produces your final dataset in the code and then alter the data .....; statement or the out= (if it is some other procedure) so that the dataset is created in a permanent library instead of work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,460

Re: A question about sas data export

And just related to the appearance: Be very careful opening CSV files in Excel (and likely some other spreadsheets) as it tries to be "helpful" and treats what you thought was a character 0008899 as a numeric. If you save the file from Excel will change the actual value.

Ask a Question
Discussion stats
  • 7 replies
  • 366 views
  • 0 likes
  • 4 in conversation