Export data from CSV into SAS in CDMS
Table of Contents
Learn how to easily export data from a CSV file into SAS in Castor CDMS. If you would like to export data directly in the SAS format, please visit the article Export into SAS.
First export your data with the export type 'CSV'.
From here there are two ways to import your Castor data in the CSV files into SAS:
- Code
- Import data directly from your folder
Code
- Move the CSV file in a directory/folder that you can easily find back.
- Open a new Program by clicking on the new file icon under "Server Files and Folders, then click "SAS Program (F4)":
- Paste the following code in the right panel.
%web_drop_table(WORK.IMPORT); FILENAME REFFILE '/folders/myfolders/sasuser.v94/test.csv'; PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT; GETNAMES=YES; DELIMITER=";"; RUN; PROC CONTENTS DATA=WORK.IMPORT; RUN; %web_open_table(WORK.IMPORT);
- Replace the file path '/folders/myfolders/sasuser.v94/test.csv' with your own file path.
- Depending on your system, your CSV file is delimited by comma (,) or by semicolon (;). You can check this by opening the file with a text editor application like Notepad or TextEdit, or just try to import first and see how your data import looks like. If your data is delimited by commas, replace the line 'DELIMITER=";";' with 'DELIMITER=",";'
- Click on the running man icon or press F3.
Import data directly from your folder
- Add the csv file into your 'sasuser' folder (directory).
- If you're not sure where this folder is located, open a new Program by clicking on the new file icon under "Server Files and Folders, then click "SAS Program (F4)":
- Paste the following code in the right panel and click on the running man icon or press F3.
%put My SASUSER folder is %sysfunc(pathname(sasuser));
- Click on "Server Files and Folders Pane" in the left panel.
- Navigate to the folder where your CSV file is stored.
- Right click on your CSV file and click "Import Data".
- Depending on your system, your CSV file is delimited by comma (,) or by semicolon (;). You can check this by opening the file with a text editor application like Notepad or TextEdit, or just try to import first and see how your data import looks like.
- If your CSV file is delimited by semicolon, click on "Code/Results" in the right panel. The code that is used for importing data is shown in the sub tab "Code".
- Click on "Edit" in the sub tab "Code".
- Add the following line under PROC IMPORT:
DELIMITER=";";
- Your code will look like the screenshot below. Click on the running man icon or press F3.
- Navigate to "OUTPUT DATA" to see your imported data.