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

Hi

Im not able to import data from neither CSV nor SAS-file from RedCap. Have tried different codes but without succes.

My data is downloaded from RedCap with output to SAS, downloading both SAS and CSV-file. 

Im using Enterprise Guide 7.1. 

 

What I've done: 

- Opened my SAS file. 
This open SAS and creates in top: 

 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny-Rawdata_DATA_NOHDRS_2021-10-27_1421.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

I then manually moved my corresponding CSV file to the library in "home" under "server". 

However, when I run this, no output file or results are created. 

I notice when I go trough the CSV file that it is comma separated. But the first 13 rows is not related to the way I set it up in RedCap. First meaningful data-including line is from 14'th row and soforth. 

 

The code: 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny_DATA_NOHDRS_2021-10-27_1441.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

proc contents data=redcap;
proc print data=redcap;
run;

 

Then I tried to download the raw CSV datafile and import it in SAS. 

This creates output data, but without the headers. 

 

Anyone with a solution ? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@rookie21 wrote:

Hi

Im not able to import data from neither CSV nor SAS-file from RedCap. Have tried different codes but without succes.

My data is downloaded from RedCap with output to SAS, downloading both SAS and CSV-file. 

Im using Enterprise Guide 7.1. 

 

What I've done: 

- Opened my SAS file. 
This open SAS and creates in top: 

 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny-Rawdata_DATA_NOHDRS_2021-10-27_1421.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

I then manually moved my corresponding CSV file to the library in "home" under "server". 

However, when I run this, no output file or results are created. 

I notice when I go trough the CSV file that it is comma separated. But the first 13 rows is not related to the way I set it up in RedCap. First meaningful data-including line is from 14'th row and soforth. 

 

The code: 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny_DATA_NOHDRS_2021-10-27_1441.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

proc contents data=redcap;
proc print data=redcap;
run;

 

Then I tried to download the raw CSV datafile and import it in SAS. 

This creates output data, but without the headers. 

 

Anyone with a solution ? 

 

 


If the process you describe is accurate you have not done anything to make a SAS data set. You would have to use a data step code or Proc Import or a task to read the CSV into a SAS data set. SAS will create CSV files but does not use them in a "native" form such as for printing or analysis.

 

If you want suggestions on how to handle a specific CSV file you should copy the first 20 lines or so, since you say you have an issue with lines around 20, and on the forum open a text box using the </> icon at the top of the message window and paste the text.  The text box is important because the message windows reformat text and so if you do not use a text box the results we see would likely not be exactly as your data exists.

 

If your method of creating a CSV yields something where the first line of the file is not the headers than import will likely have serious problems as is that expects exactly one row of header information with all subsequent rows be similarly structured data.

View solution in original post

3 REPLIES 3
AMSAS
SAS Super FREQ

Are you getting anything in the log window? Can you run it and paste the log to the post using the Insert SAS code button above

The code you are running

 

 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny-Rawdata_DATA_NOHDRS_2021-10-27_1421.csv';
libname bp '/sasfolders/user/jthu0019/BP';

Wouldn't generate any output, all it is doing is setting a macro variable (csv_file) and assigning a library reference (bp)


The later code you have

proc contents data=redcap;
proc print data=redcap;
run;

Is attempting to run a PROC CONTENTS and PRINT on a work dataset called redcap.
My guess is you want to change redcap to bp.redcap

ballardw
Super User

@rookie21 wrote:

Hi

Im not able to import data from neither CSV nor SAS-file from RedCap. Have tried different codes but without succes.

My data is downloaded from RedCap with output to SAS, downloading both SAS and CSV-file. 

Im using Enterprise Guide 7.1. 

 

What I've done: 

- Opened my SAS file. 
This open SAS and creates in top: 

 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny-Rawdata_DATA_NOHDRS_2021-10-27_1421.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

I then manually moved my corresponding CSV file to the library in "home" under "server". 

However, when I run this, no output file or results are created. 

I notice when I go trough the CSV file that it is comma separated. But the first 13 rows is not related to the way I set it up in RedCap. First meaningful data-including line is from 14'th row and soforth. 

 

The code: 

/* Edit the following line to reflect the full path to your CSV file */
%let csv_file = 'BoernepaceOkt2021Ny_DATA_NOHDRS_2021-10-27_1441.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 

proc contents data=redcap;
proc print data=redcap;
run;

 

Then I tried to download the raw CSV datafile and import it in SAS. 

This creates output data, but without the headers. 

 

Anyone with a solution ? 

 

 


If the process you describe is accurate you have not done anything to make a SAS data set. You would have to use a data step code or Proc Import or a task to read the CSV into a SAS data set. SAS will create CSV files but does not use them in a "native" form such as for printing or analysis.

 

If you want suggestions on how to handle a specific CSV file you should copy the first 20 lines or so, since you say you have an issue with lines around 20, and on the forum open a text box using the </> icon at the top of the message window and paste the text.  The text box is important because the message windows reformat text and so if you do not use a text box the results we see would likely not be exactly as your data exists.

 

If your method of creating a CSV yields something where the first line of the file is not the headers than import will likely have serious problems as is that expects exactly one row of header information with all subsequent rows be similarly structured data.

Reeza
Super User
%let csv_file = 'BoernepaceOkt2021Ny_DATA_NOHDRS_2021-10-27_1441.csv';
libname bp '/sasfolders/user/jthu0019/BP';

 proc import out=bp.redcap datafile=csv_file dbms=csv replace; guessingrows=max; run;


proc contents data=bp.redcap;
proc print data=bp.redcap(obs=10);
run;

You missed a PROC IMPORT step - see the code above.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 745 views
  • 0 likes
  • 4 in conversation