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;
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.
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.
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
Also, when I change the colon to semicolon...It says output SAS data set must be provided
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.
/*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;
How do I state it exist?
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.
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.
Sorry about that. I changed it to sample
Try this:
proc import datafile="s:\CSV Import\rapid_syphilis.csv"
and fix the OUT=
Now it says libname is not assigned...I am sorry for bugging you..I am really new at this.
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
Which kind of SAS installation are you using?
All these need different methods for accessing external files and defining libnames, so it is essential for us to know how you use SAS.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.