SAS中文论坛

标题: 关于INPUT MISSING数据的问题 [打印本页]

作者: shiyiming    时间: 2004-4-23 21:07
标题: 关于INPUT MISSING数据的问题
我有一个数据记录,其中第一个数据和第三个数据有值,但第二个数据和第四个数据为空格,而且分割符也为空格。这种情况如何输入(除COLUMN INPUT)
作者: shiyiming    时间: 2004-4-23 22:12
你的问题是不是将变量排序,由此有如下程序
data temp;
  infile 'd:\book2.txt';
  input i j@@;
  a=i; b=.;c=j;d=.;
  drop i j;
run;
其中book2.txt为
10   34
23   23
作者: shiyiming    时间: 2004-4-23 23:14
标题: 多谢
我的问题是,例如在abc.txt中文件是如下格式

12    24
其中12是第一个变量的值,第二个变量MISSING,第三个变量的值为24,第四个变量的值也为MISSING,而且变量之间的分割符为空格,在这种情况下,如何输入。
作者: shiyiming    时间: 2004-4-23 23:29
标题: Re: 多谢
[quote="smartie":bd4b2]我的问题是,例如在abc.txt中文件是如下格式

12    24
其中12是第一个变量的值,第二个变量MISSING,第三个变量的值为24,第四个变量的值也为MISSING,而且变量之间的分割符为空格,在这种情况下,如何输入。[/quote:bd4b2]

I think your have not presented your question in a good way.  If there is no data for the second variable across all records, you do not need to input it.  If there is any data for the second variable, without additional information, there is no way to read it in.  When I get the second value from a record, I should be able to know it is for variable 2 or variable 3.  The basic rule is that people have to know what they want, then find a way to implement it by program.  If people are not clear their needs, it will be out of question.
作者: shiyiming    时间: 2004-5-6 23:38
I think in this topic [b:dd839]xic[/b:dd839] misunderstood what the host meant (or
alternatively this could be the 2nd time I've incorrectly claimed the posting to be wrong!).

In some cases, we [b:dd839]do[/b:dd839] need to read some missing data files into separate variables. This is what the host intend to do, isn't it?

I just assume your dataset uses a tab as a delimiter and without the variable names at the top of the file. Try the program underneath.

proc import datafile="<pathname>" out=mydata dbms=tab replace; getnames=no;
run;

Does it work?

BTW, I have just been using SAS for a week, maybe I am totally wrong!

Cheers
作者: shiyiming    时间: 2004-5-7 03:20
The key here is that TAB contains information, Smartie did not mention it. If we ignore the TAB, only considering a data set with space as delimiter, we can see a data set with two records

12 34 23 45
23  31

When you get the second record, there is no way to find out 31 is a value of second variable or the third variable.  There must be some logics behind it which was not mentioned in the original posting.
作者: shiyiming    时间: 2004-5-7 12:48
标题: Re: 多谢
[quote="smartie":16cd2]我的问题是,例如在abc.txt中文件是如下格式

12    24
其中12是第一个变量的值,第二个变量MISSING,第三个变量的值为24,第四个变量的值也为MISSING,而且变量之间的分割符为空格,在这种情况下,如何输入。[/quote:16cd2]

Hi [b:16cd2]smartie[/b:16cd2], I am now assuming your file uses a space as a delimiter to separate variables and has 4 variables without the variable names at the top of the file(variable2&4 are all using [b:16cd2]one[/b:16cd2] space as delimiters).

proc import datafile="<pathname>\abc.txt" out=mydata dbms=dlm replace;
getnames=no;
run;

To [b:16cd2]xic[/b:16cd2]:
You are definitely correct. I have just studied SAS for a week, so considering the aspects is not as comprehensive as you:).
Could you pls try the program above to read space-delimited files into SAS? I used "proc print" to check the results, the data has been read correctly. If yours does not work properly, tell me the details pls.
Kind regards




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2