BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
geneshackman
Pyrite | Level 9

Hi all. I'm hoping this is a fairly simple question, I can't get the syntax quite right. Or else I'm making a simple typo that I just can't see.

 

%let start=18; *first year;
%let end=%eval(&start+2); *end year;
%let start4=2018;
%let end4 = %eval(&start4+2);

 

proc import out = pzip&start.&end
datafile = "\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_&start4._&end4.xlsx"
DBMS=XLSX REPLACE;
getnames = yes;
SHEET="PerinZIP_&start4._&end4";
options MSGLEVEL=i;
run;

 

The exel file is named:

PerinZIP_2018_2020.xlsx

and the sheet I want is:

PerinZIP_2018_2020

In this folder

\\dohfile02\phig\PHIGDATA\Data\perinatal_zips

 

the error i get is generally this, "Physical file does not exist"

 

316 proc import out = pzip&start.&end
317 datafile =
317! "\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_&start4._&end4.xlsx"
318 DBMS=XLSX REPLACE;
319 getnames = yes;
320 SHEET="PerinZIP_&start4._&end4";
321 options MSGLEVEL=i;
322 run;

ERROR: Physical file does not exist,
\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_2018_2020xlsx.
NOTE: The SAS System stopped processing this step because of errors.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_2018_2020xlsx

 

Macro processor ate the period. You need to have double periods for the file extension.

 

datafile = "\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_&start4._&end4..xlsx"

View solution in original post

6 REPLIES 6
Reeza
Super User

\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_2018_2020xlsx

 

Macro processor ate the period. You need to have double periods for the file extension.

 

datafile = "\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_&start4._&end4..xlsx"
geneshackman
Pyrite | Level 9
Thanks Reeza. I tried that and still got an error. I must have a typo that I just can't find. 😞


153 proc import out = pzip&start.&end
154 datafile =
154! "\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_&start4._&end4..xlsx"
155 DBMS=XLSX REPLACE;
156 getnames = yes;
157 SHEET="PerinZIP_&start4._&end4";
158 options MSGLEVEL=i;
159 run;

ERROR: Physical file does not exist,
\\dohfile02\phig\PHIGDATA\Data\perinatal_zips\perinzip_2018_2020.
geneshackman
Pyrite | Level 9

Okay, I apologize. It's a csv file, not an xlsx file. Really my bad. End of day and I wasn't careful. Sorry.

ballardw
Super User

@geneshackman wrote:

Okay, I apologize. It's a csv file, not an xlsx file. Really my bad. End of day and I wasn't careful. Sorry.


SAS was taking the easy way out on you. The DBMS = would have thrown an error if the file is actually CSV not XLSX.

The SHEET= option would thrown an error as CSV files cannot have sheets.

 

If all of these files that are name similarly mean that they are supposed to have the same content you might be much better off writing data step code to read them so all of the variables have the same properties. Proc Import on multiple similar files quite often means individual data sets end up with different properties such as variable length and sometimes type due to contents as the Procedure has to guess separately for each file what the properties are.

 

As a minimum you want to set a large value for the GUESSINGROWS option if you use Proc Import with CSV so that more of the file is examined before properties for variables are set.

Reeza
Super User

If CSV and multiple files you can avoid a macro and read all at once similar to the approach in this thread.

https://communities.sas.com/t5/SAS-Programming/Retrieve-and-clean-all-files-in-a-directory-one-by-on...

 

 

Reeza
Super User

If you're on Unix file paths are case sensitive. 
If you're using Studio, go to Servers Folders and Files. Navigate to the path and right click the file. Copy the path exactly from properties and paste that into your program. If using EG or Foundation, the same thing can be done in the Explorer window. 

 

If Windows go to the file, hold down CTRL+SHIFT+Right Click and Copy Path to get the exact path. 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 494 views
  • 3 likes
  • 3 in conversation