Hi,
I'm trying to import this dataset into SAS (it's the NHIS 2019 adult dataset). I downloaded it as a csv, but have been having trouble importing csv files into SAS, so I converted it into an excel file, which I've had success with in the past.
This is my code:
libname nh "C:\users\Jodie-Ann\Documents\ile";
proc import out=nhis
datafile = "c:\users\\Jodie-Ann\Documents\ile\adult2019.xlsx"
dbms = excel replace;
sheet = "sheet2$";
range = "A1:TN31998";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
run;
When I run I get this error:
WARNING: SHEET name will be ignored if conflict occurs with RANGE name specified.
ERROR: File _IMEX_.'sheet2$A1:TN31998'n.DATA does not exist.
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.44 seconds
cpu time 0.25 seconds
I've used this code before with a different data set that I converted from csv to excel, but not sure why it's not working this time. Any help would be appreciated, thank you!
Is there a sheet in this spreadsheet named "sheet2"? That is first thing to look for.
What happens if you don't use the RANGE statement and if you call the sheet just Sheet2 (no dollar sign on the end)?
If you don't check very closely you can find that Excel when saving a CSV can significantly change values. Really, like changing hyphenated values like 5-1, that should be character, into dates, and stripping leading zeros that are part of things like account numbers.
Please describe the exact problems you have been having with importing CSV files. One important consideration is that Proc Import only examines 20 rows of data by default before setting variable properties. So use of setting a large value for the Guessingrows option often fixes many of the issues people encounter.
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.