当前位置: 动力学知识库 > 问答 > 编程问答 >

sas - Import data from European Social Survey

问题描述:

I need to import data from European Social Survey databank to SAS.

I'm not very good at using SAS so I just naively tried importing the text file one gets but it stores it all in one variable.

Can someone maybe help me with what to do? Since there doesn't seem to be a guide on their webpage I reckon it has to be pretty easy.

It's free to register (and takes 5 secs) and I need all possible data for Denmark.

Edit: When downloading what they call a SAS file, what i get is a huge proc format and the same text file as one gets by choosing text.

The data in the text file isn't comma separated and the first row does not contain variable names.

网友答案:

Download it in SAS format. Save the text file in a location you can remember, and open the SAS file. It's not just one big proc format; it's a big proc format followed by a datastep with input code. It was probably created by SPSS (it fits the pattern of an SPSS saved .sas file anyhow). Look for:

DATA  OUT.ESS1_4e01_0_F1;

Or something like that (that's what it is when I downloaded it). It's probably about 3/4 of the way down the page. You just need to change the code:

INFILE 'ESS1_4e01_0_F1.txt';

or similar, to be the directory you placed the text file in. Create a LIBNAME for OUT that goes to wherever you want to permanently save this, and do that at the start of the .sas file, replacing the top 3 lines like so.

Originally:

LIBNAME LIBRARY '';
LIBNAME OUT '';
PROC FORMAT LIBRARY=LIBRARY ;

Change these to:

libname out "c:\mystuff\"; *but probably not c:\mystuff :);
options fmtsearch=(out);
proc format lib=out;

Then run the entire thing.

This is the best solution if you want the formatted values (value labels) and variable labels. If you don't care about that, then it might be easier to deal with the CSV like Bob shows.

网友答案:

But the website says yu can download SAS format, why don't you?

You need a delimiter if all goes into one column.

data temp;
length ...;
infile 'file.csv' dlm=',';
input ...;
run;
网友答案:

As Dirk says, the web site says you can download a SAS dataset directly. However, if there's some reason you don't want to do that, choose a comma separated file (CSV) and use PROC IMPORT. Here is an example:

proc import out=some_data
     datafile='c:\path\somedata.csv'
     dbms=csv replace;
     getnames=yes;
run;

Of course, this assumes the first row contains column names.

分享给朋友:
您可能感兴趣的文章:
随机阅读: