Learning SAS? Welcome to the exclusive online community for all SAS learners.

How do I open existing research data from a gov source?

Reply
Occasional Contributor
Posts: 7

How do I open existing research data from a gov source?

Hello all,

 

I am a Master's student and new to SAS needless to say. I have some outstanding NHIS data that I would like to use for my thesis but I am unable to open the data in SAS. I have uploaded the data to my sasuser.v94 folder but when I attempt to open it--nothing.  Your assistance would be greatly appreciated. 

 

Thanks,

Natalie

nrmagee0506@email.campbell.edu

 

When I attempt to attach the file below I get an error that "The contents of the attachment doesn't match its file type."

Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?

What format is the file? 
Post your code and log and explain what you've tried in detail. 

 

I generally don't recommend posting your email address on a forum like this unless you like a lot of spam. 

You can review the guidelines here on 'how to ask a good question' which really should be titled, how do I get a correct answer quickly.

 

https://stackoverflow.com/help/how-to-ask

Super User
Posts: 10,874

Re: How do I open existing research data from a gov source?

[ Edited ]

Depending how you downloaded the data you have gotten an actual link instead of the file.

If the data is available as Text (CSV -do not open and save from Excel or TXT extention) and they provide a "read data" program that would likely be the best approach to avoid issues with file problems.

 

With details of which file or the source location I can't get too much more specific than that.

Did you download an XLS or XLSX file perhaps? A common problem is people naming files with XLS or XLSX extensions but the actual file format is something else. Excel may read them but SAS doesn't like to be lied to.

 

As an example, If I were interested in the 2016 NHIS data set I would navigate to the data release page:

https://www.cdc.gov/nchs/nhis/nhis_2016_data_release.htm

 

and download the zipped ASCII Data file and the "Sample SAS Statements" for each topic of interest. The "Sample SAS" has example code to read the ASCII data and create SAS data sets. You would need to have everything point to the correct locations in the Libname and Filename statements.

Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

Thank you for replying to my post.

 

Still struggling. 

 

I'm sure the file is not a link. It's a file from a disk I requested from the AHRQ and uploaded to my coomputer. I just haven't been able to get it to open in SAS. It is a .dat file. (D:\MEPS_NHIS\MEPS_2012\NHMEP12X.DAT) This forum will not allow me to attach either the original file or the sasuser file.

Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?

A DAT file is a text file.

You should also have a record layout and then you need to import the DAT file, using PROC IMPORT or a data step.

 

If you have that code, that's not working, please post the code and log. 

This is an example of importing a CSV, which is also a text file but comma delimited. 

http://video.sas.com/detail/videos/how-to-tutorials/video/4573016758001/creating-a-sas-table-from-a-...

 

The same approach can be used to import your dat file.

 

You can change the extension to txt and upload the file, but only do that if it doesn't have any confidential information.

 

Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

OK. My undergrad was in English--

 

Here is code:

 

 

 

Super User
Posts: 10,874

Re: How do I open existing research data from a gov source?

It is much better to post code as plain text by pasting into a code box opened with the forum {i} menu icon.

 

Microsoft doc and docx files many users here will not open due to security risks and/or policy or security software settings. Also the doc files may change characters creating code that will not run. "Smart quotes" where the code straight " or ' get replaced with the curved open and close quotes are the most obvious.

 

If you want to attach a file use a plain TXT file such as from Notepad or other plain text editor.

 

If you are getting errors it may be best to just copy the log entry, include code and error messages, and paste that into a code box.

Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?

Ok, did you try it's suggestions?
It has the code in there, you would update the path to reflect where the DAT file is stored.

 

DATA NHMEP12X;
INFILE    “C:\TEMP\MEPS\NHMEP12X.DAT”;
INPUT  DUPERSID $1-8  HHX $9-14  FMX $15-16  FPX $17-18  LINKFLAG 19  PANEL  20-21 SRVY_YR 22-25;
RUN;
Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

I did try the suggestion in the code file. Does it matter that I'm using the SAS Univeristy Edition?

Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?


nrmagee wrote:

I did try the suggestion in the code file. Does it matter that I'm using the SAS Univeristy Edition?


 

Only to the filepath.

 

Post your full code and log.

 

Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

log?

Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?

When you submit your code, there's the log/output that shows the code ran and if there were errors. 

 

So you write the code, click the little running man, and then see the log for the status. 

A data set will be created.

 

If you've placed the text file in the MYFOLDERS you set up during instruction it will be something like:

 

DATA NHMEP12X;
INFILE   '/folders/myfolders/NHMEP12x.txt' truncover;
INPUT  DUPERSID $1-8  HHX $9-14  FMX $15-16  FPX $17-18  LINKFLAG 19  PANEL  20-21 SRVY_YR 22-25;
RUN;
Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

Occasional Contributor
Posts: 7

Re: How do I open existing research data from a gov source?

I repeated the code the just now:

 

 

 

Attachment
Super User
Posts: 18,588

Re: How do I open existing research data from a gov source?

The attached file is empty. Post your code/log and images directly in the forum will get you faster responses. Many people don't want to open attachments for security reasons.

Ask a Question
Discussion stats
  • 14 replies
  • 349 views
  • 2 likes
  • 3 in conversation