What are ways to export data from tables in SAS DI? - sas

I am very new to SAS and I have some tables in SAS DI under inventory which I need to export to text file, what are the easy to do this? Can I somehow create a program in SAS EG to display the data in there then export?

In SAS Data Integration Studio:
You can either use a File Writer or User Written Code transformations to export the table to a file. If you are using User Written Code just use a proc export Example here and DI Studio documentation here.
In SAS Enterprise Guide:
Navigate in the SAS Folder to where your table is saved and double click to open the table, then you will see in the top right the option to export/send to excel. Or you can write a proc export in a program (file-New- Program)

Related

How can I create a SAS library using existing SAS files?

I have a directory containing a set of SAS scripts, data files and also csv files. I want to now associate this directory with a library in SAS. I've created a library with the path name to the directory but the contents of the library are empty when I look via SAS but not via Windows Explorer.
How can I create a SAS library with all of these existing files inside it?
Using Windows 8 SAS 9.3
PS. New to SAS hence what is possibly a very easy question.
A SAS library can contain objects such as SAS tables, SAS views, SAS catalogs (only SAS can read this catalog, on the operating system it's just a file).
In SAS catalog you can write e.g. SAS formats, SAS macros.
To assign a library use a libname statment.
libname libref base "path_to_OS_catalog";
If you want to read a file using SAS e.g. CSV, TXT files, use a filename statment. Check a documentation for examples.
filename fileref "path_to_file";
In other words, it's correct that your library is empty, because in a OS catalog there are no SAS objects.

Converting Excel file into SAS Dataset

I'm trying to import a dataset into SAS enterprise guide, however am having trouble 'converting' my excel file into a new SAS dataset file. Any easy way to do this?
Like this:
libname LIBRARYNAME 'filesource...'
data Project2
set exdata.Project;
<math>
run;
But the file I have the data in is a Excel file... and it can't find it
You are close, if you have to ability to access local files something like this may work. You may need to play around with the sheet name. Open the library once it's assigned to see how SAS refers to the sheets.
Libname mylib XLSX 'path to XLSX file';
Data want;
Set mylib.sheet_name;
Run;
Libname mylib;
Otherwise if your using EG on a server and your excel file is local you can import using the GUI tool.
In Enterprise Guide, you can create an import step. This is preferable for EG projects that will always be in EG, as it is OS-agnostic, server-agnostic, and version-agnostic, and leaves a single step on the process flow that you can move around where you need it to be run.
Choose (File menu) -> (Import Data), and then it will guide you through importing the file. When it completes, this will leave on your process flow an Import Data step that you can link to other programs (if you're using this program repeatably).
During that wizard, you will tell it what dataset name you want it saved as, and that will then exist as a SAS dataset in your project (usually in the work library unless you specify otherwise).

Export .sas7bdat from SAS Studio to local machine

I am using SAS Studio(completely browser based). I need to export a dataset to my local machine in the .sas7bdat file format. I think it should be something like PROC EXPORT data = sqrtReg2 outfile = "C:\Documents\SAS\Target_Wins.sas7bdat";. But that returns the error ERROR: Unable to determine datasource type. Please use the DBMS= option.. But the DBMS option only allows for CSV, tab and DLM. How do I export this data set to my local machine in the .sas7bdat file format?
With the SAS University Edition you can setup shared folders in the virtual machine where SAS runs that are mapped to actual folders on your real machine.
For example you might have mapped C:\Documents\SAS\ to /folders/myfolders. You cannot write to other locations on your real machine that are not mapped so that the virtual machine can see them. Check the documentation for exact details of getting the folders mapped.
The normal way to have SAS place a dataset then is to create a libref that points to the folder and then use a two level name when referencing the data set. You could create a libref named OUT for example:
libname out '/folders/myfolders/';
data out.target_wins;
set sqrtReg2;
run;
But you can also just refer to the file directly without first creating a libref.
data '/folders/myfolders/target_wins';
set sqrtReg2;
run;
Note that since SAS is actually running in Unix you cannot use CamelCaseFileNames for your SAS datasets. The files will always be in all lowercase letters.
None of the answers worked for me. Maybe because after April 2021, they have made changes to the platform(University). So, after a lot a time searching, I found what I needed.
You can easily export the sas dataset to csv, xslx, by just right clicking on the dataset and selecting export as csv, xlsx, etc.
For exporting to sas7bdat file, do:
Create your dataset, I am creating from csv, so create a program1(.sas) to first convert csv to sas dataset.
proc import file="/home/u123/mydata.csv"
out=work.mydata
dbms=csv
replace;
run;
This will create your sas dataset.
IMP Go to "Libraries" at the right bottom, and hit "My Libraries" -> New Library -> Name it(eg - test), give path(eg - /home/u123/sasuser.v94)
Check library creation, and HIT "Refresh Library Session" on right pane, don't refresh the page.
Now create a separate program2(.sas), to export the dataset to .sas7dbat file.
PROC COPY IN=WORK OUT=test;
SELECT mydata;
run;
quit
This will create a .sas7bdat file in your directory, with same name as your dataset.
These exact steps worked out for me.
It won't work for 2 reasons.
You can't export a SAS dataset to a SAS dataset (.sas7bdat) - Proc Export will export to excel, csv, etc but not to a .sas7bdat.
you're running SAS Studio from within a Virtual Machine that uses Linux as OS so path to create an external file is incorrect. You haven't hit this error but you will once you use the right filetype.
When you installed SAS Studio you should have created a shared folder. This folder is accessed from within SAS Studio as /folders/myfolders/filename.
So your code should looks like this:
PROC EXPORT data = sqrtReg2
outfile = "/folders/myfolders/Target_Wins.csv";
run;
From Windows the path to this shared folder will depend upon where you installed your VM.
Option 2
If what you need is the dataset then try the following code:
libname out "/folders/myfolders/";
proc copy in=work out=out;
select sqrtReg2 ;
run;
Again, table will be in your shared folder which is accesible from Windows.
I used just like option 2 in the above answer. I need to export my polygon data from SAS Studio in my virtual machine so that i can import it to my Visual Analytics. and it worked just fine.
libname out "/folders/myfolders/";
proc copy in=work out=out;
select my_map;
run;

Read large tables from Teradata into SAS via DI Studio for further processing

I am creating a ETL job in SAS DI Studio to read Teradata table into SAS, then to apply user written code on top of it and then load the SAS work table into Teradata again using Teradata Table Loader.
What is the best way to read the large teradata table (50Cr or more records) into SAS work space? I am currently using following Base SAS code to create a work table:
data work.out_table;
set db.in_table;
<sas-statements>;
run;
Try adding FASTEXPORT=YES option in the Library reference for Teradata or adding dataset option for the Input table within Table option tab of Append or TableLoader transformation.
I'm assuming you are on Teradata 13 > greater. If you are using older version then instead of FASTEXPORT=YES use DBSLICEPARM=ALL parameter. Since FASTEXPORT uses TPT API and that was introduced from Teradata 13 onwards.

PROC EXPORT ignoring Replace option

I have a SAS program which exports several tables to an Excel workbook. If the sheet specified in my PROC EXPORT does not exist in the Excel file, then a new sheet is created. However, if the sheet already exists, then nothing happens (although the SAS log tells me that the file was "successfully created"). It does not overwrite the existing data or create a new sheet.
I am using SAS 9.4 and exporting to Excel 2010.
proc export data=my.thing
outfile= "C:\Folder1\Folder2\myExcelFile.xlsx"
dbms=xlsx replace;
label;
sheet='thing';
run;
Your proc export statement looks okay. Perhaps the problem is when you're trying to overwrite the existing excel file. When you try to replace them, the existing excel file may not be in the expected format as the exporting excel file. Hence, there is trouble overwriting it. Look at the width of the variables in your existing excel and compare it with the new sheet "thing", maybe you can spot some inconsistencies.