由买买提看人间百态

topics

全部话题 - 话题: truncover
1 (共1页)
p********a
发帖数: 5352
1
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
如果没有TRUNCOVER,SAS读第一个OBS最后一个变量的时候,读22-37,但是Maple Ave.
没有16位长,SAS就继续读下一行,把Sylvia读成第一个OBS的STREET的一部分。
TRUNCOVER就是告诉SAS,最后一个变量,有多长就读多少,不要扯到下一个去。
f********m
发帖数: 197
2
来自主题: Statistics版 - 但谁能解释下truncover 吗?
这里用的是list input,daisyyellow之间没有delimeter,所以只读进去前5字母作为
Type.后面的字母当成是第一个variable的一部分,被忽略了。跟truncover的用法无关。
而如果用Column input或者format input并且最后一个variable的长度取到了行末,例如
input Type $ 1-5 Color $ 6-17;
这时候不用truncover的话得到的是
Type color
daisy
用的话则得到
Type color
daisy yellow
:)
s***1
发帖数: 343
3
确实很菜的问题,不要拍我,要拍也请轻拍。
感觉理论上对于column format读入的情况,如果最后一个变量值的实际长度短于定义
的长度,那么missover会assign一个missing value,而truncover会assign那个实际值
,但是下面这段却都assign了真值,想不明白为什么。
data t;
infile cards (missover/truncover);
input num 3.;
cards;
1
12
121
;
proc print;
run;
m*****8
发帖数: 27
4
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
请问TRUNCOVER起的作用是什么,附件里Little SAS Book的这段话我不太懂,哪位高手
给解释一下啊?谢谢!
p********a
发帖数: 5352
5
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
Yes for column input. I am talking about the SAS length, not the visual "non
-blank" length. Here "input street $22-37" defines the length of street is $
16. If it is less than 16 characters, there should be trailing blanks.
Truncover is just the opposite of default option-Flowover. For flowover, if
the reading pointer reaches the end of record AND the length is less than 16
, it will go to the next line.
You can do a test- just put blanks at the end of the street field so it is
16 characters lo
d*****g
发帖数: 4081
6
有这么一句我想翻到R里面用
INFILE LOCATION(**.txt) truncover FIRSTOBS = 2 DLM = ',.';
高手给解释一下吧!!谢谢了
h****9
发帖数: 26
7
来自主题: Statistics版 - 但谁能解释下truncover 吗?
Item 59 of 70 Mark item for review
Given the contents of the raw data file TYPECOLOR.DAT:
----+----10---+----20---+----30
daisyyellow
The following SAS program is submitted:
data FLOWERS;
infile 'TYPECOLOR.DAT' truncover;
length
Type $ 5
Color $ 11;
input
Type $
Color $;
run;
What are the values of the variables Type and Color?
A.
Type=daisy, Color=yellow
B.
Type=daisy, Color=w
C.
Type=daisy, Color=daisyyellow
D.
Type=
j******o
发帖数: 127
8
来自主题: Statistics版 - 但谁能解释下truncover 吗?
TRUNCOVER
Forces the INPUT statement to stop reading when it gets to the end of a
short line. This option will not skip information.
PAD
Pads short lines with blanks to the length of the LRECL= option.
MISSOVER
Sets all empty vars to missing when reading a short line. However, it can
also skip values.
s***1
发帖数: 343
9
非常感谢你给的SUGI26链接!
但是我在自己机器上用sas9.1试了里面的example,用的column input,试了missover
和truncover,但是结果竟然都是一样的,都是:
Obs lastn Firstn Empid Jobcode
1 LANGKAMM SARAH E0045 Mechanic
2 TORRES JAN E0029 Pilot
3 SMITH MICHAEL E0065
4 LEISTNER COLIN E0116 Mechanic
5 TOMAS HA... 阅读全帖
p***7
发帖数: 535
10
来自主题: Statistics版 - sas base (70) problem 59 help
----5----10---
daisyyellow
data flowers;
infile 'typecolor.dat' truncover;
length type $ 5 color $ 11;
input type $ color$;
run;
what are the value of variable type and color?
answer type=daisy color=
what I don't understand is the value of color. How does truncover work?
I look up some definition in sas documentation as followed.
Missover can replace truncover here? which will has the same result?
MISSOVER
causes the DATA step to assign missing values to any variables that do not
have values wh... 阅读全帖
m*****8
发帖数: 27
11
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
那如果这件事发生在中间而不是末尾的话(加入Maple Ave在中间,22-37也是指中间的
话),SAS应该不会继续读下去吧?

Ave.
p********a
发帖数: 5352
12
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
SAS will read exactly 16 characters if the field street is in the middle
m*****8
发帖数: 27
13
来自主题: Statistics版 - 关于SAS里TRUNCOVER一问
如果这样的话,所有的column input,不同的observation的变量长度应该一样喽?
o****o
发帖数: 8077
14
来自主题: Statistics版 - 问个SAS 数据读入的问题
try the following code. At least on my PC, given the data structure, it
works on the data sets downloaded from the website
the point is to use Text Pointer in Data step;
/* take final.csv as one of the csv file on the website*/
filename final "c:\final.csv";
data test;
infile final delimiter=',' truncover dsd;
input @"MISO Wide,-," type :$10. HE1-HE23;
if ^missing(type) then output;
run;
t**i
发帖数: 688
15
来自主题: Statistics版 - SAS infile input 问题
我的数据是tab格式化的,几万列。都是字符变量,尽管是数字构成的。请教如何确保
SAS读入的时候采用字符型变量格式?
下面这个好像不行。
infile “myfile”firstobs=1 lrecl=1000000 truncover;
input v1 - v50000 $ ;
t**i
发帖数: 688
16
来自主题: Statistics版 - SAS infile input 问题
Example code? Like the following?
data test;
infile 'myfile' firstobs=1 dlm=',' lrecl=10000000 truncover;
length v1 - v50000 :$12 ;
input v1 - v50000;
run;
Y**********8
发帖数: 67
17
好吧!暂时先承认下来
确实还处于扫盲阶段
ADV tutor还没看完
不过您这鄙视有点赤裸裸了
如此傲慢的版大
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
受刺激之下运行以下的程序,
DATA models;
INFILE 'd:\MyData\Models.dat' TRUNCOVER;
INPUT Model $ 1-12 Class $ Price Frame $ 28-38;
RUN;
%LET bikeclass = Mountain;
* Use a macro variable to subset;
PROC PRINT DATA = models NOOBS;
WHERE Class = "&bikeclass";
FORMAT Price DOLLAR6.;
TITLE "Current Models of &bikeclass Bicycles";
RUN;
证明确实不是非正版SAS的问题。是我的问题。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b******e
发帖数: 539
18
来自主题: Statistics版 - weird SAS
加一行code在input statement前:
infile datalines truncover;
g*******y
发帖数: 380
19
来自主题: Statistics版 - 有关IMPORT EXCEL FILE 的问题
sorry, maybe it should be truncover.
d*******1
发帖数: 854
20
比如你的SAS文件叫test.
data test;
a=1;b=1; output;
a=2;b=2; output;
run;
用下面的code, SAS-> CSV-> SAS-> 加# -〉CSV
proc export data=test
outfile='c:\test.csv' replace;
run;
data testx;
infile 'c:\test.csv' truncover;
input raw $1-100;
run;
data testx;
set testx;
if _n_=1 then raw='#'||trim(left(tranwrd(raw,',',',#')));
run;
data _null_;
set testx;
file 'c:\testx.csv' dlm='09'x;
put raw;
run;
j******o
发帖数: 127
21
来自主题: Statistics版 - 但谁能解释下truncover 吗?
这里有个解释,看一下:
http://www.masil.org/sas/input.html
y****n
发帖数: 46
22
来自主题: Statistics版 - 请教一个SAS数据input的问题
data temp;
length id refid $12;
infile cards truncover ;
input @;
id=scan(_infile_,1,' ///');
i=2;
do while (scan(_infile_,i,' ///') ne ' ' );
refid=Scan(_infile_,i,' ///');
output;
I=i+1;
end;
keep id refid;
cards;
1 NP_001003407/// NP_001003408 /// NP_002304 /// NP_006711
2 NP_001135417 /// NP_001604
3 NP_00499494
;
run;
y****n
发帖数: 46
23
来自主题: Statistics版 - 问一个数据分析的问题
I don't know if this is what you want.
data kids;
length temp_days $100;
infile datalines dlm=' ' truncover;
input subj origin $ sex $ grade $ type $ temp_days $;
wn=countw(temp_days,',');
do rec=1 to wn;
days=input(scan(temp_days,rec),best.);
output;
end;
drop temp_days wn;
datalines;
1 A M F0 SL 2,11,14
2 A M F0 AL 5,5,13,20,22
run;
s******y
发帖数: 352
24
来自主题: Statistics版 - 用SAS找单词
this is where Regx come in handy.
data test;
infile cards truncover;
input text $150.;
Master_stat=^^prxmatch('/(?<=statistics\s{20})Masters|Masters(?=\s{20}
statistics)/io',text);
cards;
The department of statistics Masters
The department of statistics Masters
masters statistics sucks
;
run;
proc print;
run;
j**********e
发帖数: 442
25
您真是太谦虚了。这样确实就可以work了。给您发了20个伪币,聊表寸心。
有个问题是:根据上面的代码,在company和000007之间只能有:而不能有任何空格。有没有办法允许在:后有空格呢?
我才搞清楚,原来是中文的问题。中文一个字占两格,所以在读取冒号后面的值时有困难(到底为啥困难我也不明白)。我把冒号删除了然后在英文输入法环境下再添上冒号就可以了。但是文件太多,一个一个这样弄太费时间。大家有好办法吗?
附上整个宏(测试用,所以num只从0到1):
%macro input_file;
%do num=0 %to 1;
data file_sub;
infile "C:\research\A (&num).txt"
firstobs=1

delimiter=":" truncover;
input col_1 $20. ;
n=_N_;
if n=1 then company=scan(col_1,2,':');
retain company;
if n=4 then date=in
s******y
发帖数: 352
26
来自主题: Statistics版 - 问个SAS 数据处理问题
that is so called brotherhood, right.
well, I thin you asked how to add quotation mark to each word in the
sentence. the QUOTE function merely add one at begining and one at the very
end.
so for this task, I would like to use Regex. it is one liner solution. but
certainly, you can loop through and add the quotation mark for each word
delimited by space.
any way here is the code:
data _null_;
infile cards truncover;
length quoted_line $600.;
input line $200.;
quoted_line=prxchange('s/([\w''""]+)(
s*******r
发帖数: 769
27
来自主题: Statistics版 - 也问几道SAS base 题目
为什么选D?
----+----10---+----20---+----30
daisyyellow
The following SAS program is submitted:
data FLOWERS;
infile 'TYPECOLOR.DAT' truncover;
length
Type $ 5
Color $ 11;
input
Type $
Color $;
run;
What are the values of the variables Type and Color?
A. Type=daisy, Color=yellow
B. Type=daisy, Color=w
C. Type=daisy, Color=daisyyellow
D. Type=daisy, Color=
a*****3
发帖数: 601
28
变量‘的个数’ not length.
l**********9
发帖数: 148
a*****3
发帖数: 601
30
关于sugi,有没有根目录或是分类啥的? 比如哪篇paper在哪个分类。下回便于查找。
k*******a
发帖数: 772
31
这个应该不是版本的问题。
如果你用的是datalines, 那么每行你的数据后面都加上很多空格(你看不到),但是
程序读你数据的时候,把空格读进去了,也就不会miss掉。
如果你把数据放到文件里面,那么数据后面不会有空格,而是endofline,所以
missover的时候,读pilot因为独到endofline所以就以为数据不全,读为miss

missover
s***1
发帖数: 343
32
明白了,非常感谢!
D******n
发帖数: 2836
33
来自主题: Statistics版 - sas 数据输入问题
baozi....
data a1;
infile './temp.txt' truncover;
input type @;
do until(0);
input weight @;
if weight=. then leave;
else output;
end;
run;
s*****p
发帖数: 299
34
来自主题: Statistics版 - 请教SAS BASE 70题里的第59题
Given the contents of the raw data file TYPECOLOR.DAT
daisyyellow
the following SAS program is submitted:
data FLOWERS;
infile 'TYPECOLOR.DAT' truncover;
lenth
Type$5
color $11;
input
Type $
Color $;
run;
What is the value of the variables Type and color?
answer: Type=daisy, color=
多谢!!
d******9
发帖数: 404
35
你如果不用 missover, truncover, Input 语句自然会跳到下一行啊。It will read "
5, 6" from next line and assign them to r4, r5, respectively.
s******y
发帖数: 352
36
filename temp temp;
data _null_;
length temp $200.;
retain temp;
file temp;
infile datalines eof=end;

input;

if not missing(temp) and prxmatch("/^\s*\d{3}\s*/",scan(_infile_,1,
','))=0
then do;
temp=cats(temp,_infile_);
return;
end;
else if _n_>1 and prxmatch("/^\s*\d{3}\s*/",scan(_infile_,1,','))>0
then put temp;
temp=_infile_;
return;
end:put temp;
da... 阅读全帖
s******y
发帖数: 352
37
来自主题: Statistics版 - 请教用SAS的一个数据处理的问题
DATA HAVE;
INFILE CARDS TRUNCOVER;
INPUT A B C D;
ROWID=_N_;
CARDS;
1
7
3 3
2 5
. 5
. 5 3
. . 4 5
. . 5 8
. . 2 3
. . . 1
;
RUN;
PROC TRANSPOSE DATA=HAVE OUT=HAVE1(WHERE=(NOT MISSING(COL1)));
BY ROWID;
VAR A B C D;
RUN;
PROC SORT DATA=HAVE1;
BY _NAME_ ROWID;
RUN;
DATA HAVE2;
SET HAVE1;
BY _NAME_;
ID+1-(FIRST._NAME_)*ID;
RUN;
PROC SORT DATA=HAVE2;
BY ID _NAME_ ;
RUN;
PROC TRANSPOSE DATA=HAVE2 OUT=WANT(DROP=_NAME_ ID);
BY ID ;
VAR COL1;
ID _NAME_;
RUN;
k*******a
发帖数: 772
38
来自主题: Statistics版 - 请教个有关SAS 的问题
dsd 后面加个 truncover 试试看
u*********r
发帖数: 1181
39
来自主题: Statistics版 - 请教个有关SAS 的问题
不行啊,我有大概20多个变量,每个变量都是24个obs,然后6个treatment,包括control (
4obs each)
然后就是简单的做个与对照组control的比较 显著性比较
加了你的truncover
开始几个参数读的正确了,但是后来大部分就不读了,print 检查一下都是空白
y******e
发帖数: 33
40
早上basic 归来。因为暑假实习开始正式的使用SAS,就想趁着这个机会把考试都考了
。于是报名了今早的BASIC. 因为是学生有半价,90大洋。
具体学生半价介绍如下:http://support.sas.com/certify/faq.html# Q2
约的9点半,但是8点半就到了。然后没人考,小秘很nice,9点就开始考了。用了一个
小时不到答题,然后检查了半个小时,结果是87%。比预计的差一点,不过过了就够啦
:)
真正的接触SAS 3个月,但是正式的备考不到两周吧。因为每天白天要上班上学没法看
,只能用晚上。看完了那个BASIC 的书,22章大概一天看个4章左右,用了7天吧。然后
123题用了一天,70题一天,50题一天。最后两个晚上看了看每一章的summary。其实每
次都是看着电视剧准备的,所以这个结果还是挺满意的。
考试刚开始有个tutorial,就是给你一个直观的印象。我之前是没有用过online的,所
以这个tutorial还是满有用的。
开始答题,不确定的就mark,答完不到50分钟,回头数了数mark大概二十多个,这个比
较恐怖啊,又重新过一遍mark,减少到1... 阅读全帖
l***a
发帖数: 12410
41
我以前弄过一个类似的步骤,code改一下帖这里,后面主要是import你可能用不到
options noxsync noxwait noxmin;
x "dir /b /s yourpath\import.csv";
options mprint mlogic;
%macro import(file, name);
data _&name.;
infile "&file";
run;
proc append base=total data=_&name. force;
run;
%mend import;
proc datasets lib=work;
delete total;
run;
data import;
infile 'yourpath\import.csv' truncover;
input file $100.;
length=index(upcase(reverse(scan(reverse(file),1,'\'))),'.TXT');
length name $20.;
if length>0 then do;
name=substr(revers... 阅读全帖
d******9
发帖数: 404
42
来自主题: Statistics版 - HELP~~About reading sas data set
By default, if SAS can not find values for all the variables defined in
INPUT statement, it will automatically go to NEXT record to read the values
until it get all the values for all the vars.
This is called FLOWOVER, which is the default mode in SAS data step.But, as
you have seen, it may make trouble and destroy the data totally. So,
sometimes we have to disable it.
In this case, we may use Missover/TruncOver/StopOver options in INFILE
statement depending on situations.
For details, view ... 阅读全帖
a********0
发帖数: 81
43
来自主题: Statistics版 - SAS base归来 一点小经验
不相关专业小菜鸟一枚sas base归来,虽然版上许多大牛已经base advance高分
双丰收了,我还是写点我的经验吧。
7.17早上9:45的sas base 提前一个多小时到。休息室很温馨,有免费的咖啡巧
克力和energy bar电视机里还放着base ball俨然木有考试的紧张氛围。过了一会接待
的MM到了也很nice的问我是想在学习一会还是马上去考,于是九点不到我就进入了exam
area。顺便唠叨一句,考试证件只需要带照片的ID,我就给她看了我的permit,学生
证应该是不行的。进入考场之前会给你读一个考试相关细则让你签字,基本内容就是进
入考场什么也不能带。他会给你两个board和一个mark笔做记录,但基本也用不太到。
2小时70道题目我碰到的都是选择题,70%就算PASS。时间绰绰有余,大家静心仔
细做题就好。很多都是50,70,123的原题,当然也有相关概念题,所以大家做题目的
时候尽量把不太懂的概念也弄懂,不要以为光背原题就好了。比如一道truncover的题
目我就觉得似曾相识他却不认识我。当然碰到原题的感觉还是很爽的,... 阅读全帖
j******o
发帖数: 127
44
来自主题: Statistics版 - How to import several excel files together?
昨天刚写了几段code,不过是对csv的,请你改一下用在Excel文件上吧。中间有些地方
可能不太完善(比如文件名不能有空格等),欢迎改进及简化。
----------------------------------------------------------------
libname backup "C:\Documents and Settings\Ying\Desktop\Test";
filename blah pipe 'dir "C:\Documents and Settings\Ying\Desktop\Test\*.csv"
';
data dirlist;
infile blah truncover lrecl=200;
input line $200. ;
if upcase(substr(line, 1, 9))='DIRECTORY' then call symput('direc', trim
(substr(line, 14, length(line))));
if input(substr(line,1,10), ??... 阅读全帖
s******y
发帖数: 352
45
来自主题: Statistics版 - SAS MACRO question (包子求教重金酬谢)
%let dirpath=d:;
filename csvfile pipe "dir /b &dirpath.\*.csv";
data allcsv;
infile csvfile lrecl=1000;
input;
fname=catx('',"&dirpath.",_infile_);
infile dummy filevar=fname filename=myfile end=done firstobs=4
dsd truncover;
do while(not done);

input date :date9. Tier :$50. Ccy :$50.
Doc :$50. Sd1y :percent. Sd2y :percent.;

output;
end;
put 'Done with ' myfile=;
run;

external
w**********i
发帖数: 4
46
来自主题: Statistics版 - 请教下SAS Base 70题的第59题
请大牛指点下第59题。
59.Given the contents of the raw data file TYPECOLOR.DAT:
----+----10---+----20---+----30
daisyyellow
The following SAS program is submitted:
data FLOWERS;
infile 'TYPECOLOR.DAT' truncover;
length
Type $ 5
Color $ 11;
input
Type $
Color $;
run;
What are the values of the variables Type and Color?
A. Type=daisy, Color=yellow
B. Type=daisy, Color=w
C. Type=daisy, Color=daisyyellow
D. Type=daisy, Color=
Answer: D... 阅读全帖
c*****a
发帖数: 177
47
来自主题: Statistics版 - 请教下SAS Base 70题的第59题
truncover is equivalent to missover+padding. So A should be the correct
answer even though "yellow" is a shorter string.
t*********e
发帖数: 313
48
来自主题: Statistics版 - 请教下SAS Base 70题的第59题
data test;
infile datalines truncover;
length
Type $ 5
Color $ 11;
input
Type $
Color $;
datalines;
daisyyellow
;
run;
j********t
发帖数: 201
49
来自主题: Statistics版 - ask for help on one SAS code
you might just read in all data first then process each record afterwards
using character functions or Perl Regular Expressions.

data one;
input title $ Pet_owner $ pet $ number;
length name $20.;
name=compress(title)||' '||compress(pet_owner);
cards;
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data one: if one(or more) space(s) always exist(s) between the title
and the name";
run;
data two;
input title $ Pet_owner $ pet $ number;
length nam... 阅读全帖
k******w
发帖数: 269
50
来自主题: Statistics版 - SAS 求助: filenames
filename lib pipe "dir C:Downloads*.dta /b";
data file;
length filenames $ 60;
infile lib truncover;
input filenames : $;
filenames="C:Downloads"||filenames;
run;
proc sort data=file; by filenames;run;
data null;
set file;
call symputx('file'||put(_n_,z2.),filenames,'G');
run;
_________________
假设我有21个files,从0.dta 到 20.dta
我希望能按数字顺序import到file里,可是结果顺序是:
0
1
11
12
13
.
.
.
19
20
21
3
4
5
...
哪位高手指点一下,多谢!
1 (共1页)