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

Hello there! i am a new SAS user and I am trying to import a CSV file...I have already created a folder in SAS where the csv file is..The problem is that when I press run, it keeps saying physical file does not exist...The folder name is rapid_syphilis and the csv in it is named sample_8.3.2020...

 

Here is my code:

/*import a CSV file*/

%let path=S:\CSV Import;

options validvarname=v7;

 

proc import datafile="&path\rapid_syphilis.csv"

                   out=syphilis

                   dbms=csv replace;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

When you have a macro variable that has a value of S:\CSV Import then your code uses it in this line

 

 

proc import datafile="&path\rapid_syphilis.csv"

and so &path is replaced by S:\CSV Import and so now SAS is looking for the file

 

S:\CSV Import\rapid_syphilis.csv

 

and the ERROR message you are getting is that this file does not exist. You are pointing in the wrong folder, or you have the wrong file name.

 

Side issue: you don't need a macro variable here at all. Just get rid of it and type in the correct folder and file name in PROC IMPORT. Especially for a beginner, it's easier to get the file name and folder correct by typing it in yourself than by resorting to a macro variable.

 

--
Paige Miller

View solution in original post

27 REPLIES 27
PaigeMiller
Diamond | Level 26

When you have a macro variable that has a value of S:\CSV Import then your code uses it in this line

 

 

proc import datafile="&path\rapid_syphilis.csv"

and so &path is replaced by S:\CSV Import and so now SAS is looking for the file

 

S:\CSV Import\rapid_syphilis.csv

 

and the ERROR message you are getting is that this file does not exist. You are pointing in the wrong folder, or you have the wrong file name.

 

Side issue: you don't need a macro variable here at all. Just get rid of it and type in the correct folder and file name in PROC IMPORT. Especially for a beginner, it's easier to get the file name and folder correct by typing it in yourself than by resorting to a macro variable.

 

--
Paige Miller
Kimberly_2020
Calcite | Level 5

Now it is giving me a syntax error for:

 

proc import datafile= s:\CSV Import\rapid_syphilis.csv

 

The line is under the colon..it says it is not recognized and will be ignored

Kimberly_2020
Calcite | Level 5

Also, when I change the colon to semicolon...It says output SAS data set must be provided 

PaigeMiller
Diamond | Level 26

First, I don't think you have actually stated that s:\CSV Import\rapid_syphilis.csv actually exists, and SAS thinks it doesn't exist, so I believe SAS.

 

Show us the LOG from this portion of the code. Do not chop anything out. Copy the log as text and then use the </> icon here to open a window which the log should be pasted into — do not skip this step.

--
Paige Miller
Kimberly_2020
Calcite | Level 5
/*Import a CSV File*/
%let path=S:\CSV Import;
options validvarname=v7;

proc import datafile= s:\CSV Import\rapid_syphilis.csv
			out=sample_8.3.2020.csv
			dbms=csv replace;
run;
Kimberly_2020
Calcite | Level 5

How do I state it exist? 

PaigeMiller
Diamond | Level 26

You did not show me the LOG from your code. I need to see the LOG including the code, NOTES, WARNINGs and ERRORs.

 

You confirm that the file exists by showing me a screen capture of the folder so we can all see what files are in it.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Adding, this is probably the error

 

out=sample_8.3.2020.csv

you have to use a valid SAS data set name here, which can't have periods, spaces or any special characters except an underscore. Which is why you really need to show us the log in the first place, this would have saved lots of time.

--
Paige Miller
Kimberly_2020
Calcite | Level 5

Sorry about that. I changed it to sample

PaigeMiller
Diamond | Level 26

Try this:

proc import datafile="s:\CSV Import\rapid_syphilis.csv"

and fix the OUT= 

--
Paige Miller
Kimberly_2020
Calcite | Level 5

Now it says libname is not assigned...I am sorry for bugging you..I am really new at this. 

Kimberly_2020
Calcite | Level 5
libname syphilis "/home/u49152645/syphilis";

Note:

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         libname syphilis "/home/u49152645/syphilis";
 NOTE: Library SYPHILIS does not exist.
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 87         
Reeza
Super User
You need to show your whole code and log. We're seeing bits and pieces that don't make sense.
Kurt_Bremser
Super User

Which kind of SAS installation are you using?

  • University Edition in a downloaded virtual machine
  • SAS on Demand for Academics
  • licensed SAS in a local installation
  • licensed SAS in a client/server installation

All these need different methods for accessing external files and defining libnames, so it is essential for us to know how you use SAS.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 27 replies
  • 4109 views
  • 2 likes
  • 5 in conversation