BookmarkSubscribeRSS Feed
J-Ann
Fluorite | Level 6

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! 

7 REPLIES 7
CurtisMackWSIPP
Lapis Lazuli | Level 10

Is there a sheet in this spreadsheet named "sheet2"?  That is first thing to look for.

J-Ann
Fluorite | Level 6
Hi,
Yes Sheet2 is the one with all the data-points.
SASKiwi
PROC Star

What happens if you don't use the RANGE statement and if you call the sheet just Sheet2 (no dollar sign on the end)?

Reeza
Super User
It's almost always easier to import CSV files and I would recommend you switch back. The quick lazy "trick" is to first run PROC IMPORT on your CSV file and then copy the code from the log and customize/correct it as needed. Most government data is designed to be imported via SAS so I'd give that a shot if you can. If you have issues, it is a public file so post the link and someone can likely help with the code needed to read the CSV.
ballardw
Super User

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.

 

 

Reeza
Super User
Don't they provide the INPUT code for these files?
https://www.cdc.gov/nchs/nhis/2019nhis.htm

Using that with the CSV should get you what you need...
J-Ann
Fluorite | Level 6
I tried again with the csv file and it worked! I'm not sure what was happening with it the first time I tried, but I've got it now! Thanks everyone

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
  • 7 replies
  • 1258 views
  • 7 likes
  • 5 in conversation