s********1 发帖数: 54 | 1 Compare data inf123 and data inf, who can explain to me why outputs from
these two codes are not the same? Data inf is the right one. In terms of the
difference, they are represented as follows:
In data inf123
length readd $10.;/*先把長度都開好*/
input group id_n name $ job $12. st_time $10.;
In data inf
length job $12 readd $10 st_time $10;/*先把長度都開好*/
input group id_n name $ job $ st_time $;
______________________________________________
data inf123 ;
length readd $10.;/*先把長度都開好*/
... 阅读全帖 |
|
r******m 发帖数: 369 | 2 你的第三行第三个数据格式错了吧
data test (drop=i);
infile cards;
input id T1:mmddyy10. T2:mmddyy10. T3:mmddyy10. T4:mmddyy10.;
array T{1:4} T1-T4;
do i=4 to 2 by -1;
if T{i}=T{i-1} then T{i}=.;
end;
format T1-T4 mmddyy10.;
cards;
1 1/1/2011 1/1/2011 3/1/2011 5/1/2011
2 3/1/2009 8/1/2009 8/1/2009 10/1/2009
3 5/1/2008 8/1/2008 5/12008 11/2/2008
run; |
|
j******o 发帖数: 127 | 3 Try this.
data one;
input id dt1 : mmddyy10.;
format dt1 mmddyy10.;
datalines;
1 4/4/2000
1 4/7/2005
1 9/2/2002
2 3/1/2003
2 2/3/2006
3 5/5/2009
;
run;
data two;
input id dt2 : mmddyy10.;
format dt2 mmddyy10.;
datalines;
1 5/1/1999
1 1/1/2007
2 9/8/2002
2 10/1/2002
2 1/2/2006
;
run;
proc sql;
create table obtain as
select a.id, coalesce(a.dt1, b.dt1) as dt1 format mmddyy10., b.dt2
from one a left join
(
select one.*, ... 阅读全帖 |
|
w*******t 发帖数: 928 | 4 嗯,练了一下。学习了。
data A;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 10/12/2010
111 05/14/2010
111 01/04/2008
222 05/25/2009
333 02/15/2009
333 03/15/2010
;
run;
data B;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 02/14/2010
222 04/20/2006
333 03/14/2010
; run;
PROC FASTCLUS maxiter=0 seed=B replace=NONE data=A out=AB(drop=cluster)
MAXCLUSTERS=999;
var date;
run;
proc sort data=ab; by id distance; run;
data |
|
s******r 发帖数: 1524 | 5 haha,
you only keep one copy if there are two record in a with same distance.
try following. check 333
data A;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 10/12/2010
111 05/14/2010
111 01/04/2008
222 05/25/2009
333 03/12/2010
333 03/16/2010
;
run;
data B;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 02/14/2010
222 04/20/2006
333 03/14/2010
; run;
PROC FASTCLUS maxiter=0 seed=B replace=NONE data=A out=AB(d |
|
o****o 发帖数: 8077 | 6 switch B and A in seed= and data=
/******************/
data A;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 10/12/2010
111 05/14/2010
111 01/04/2008
222 05/25/2009
333 02/15/2009
333 03/15/2010
;
run;
data B;
infile cards;
input id $ date mmddyy10.;
format date mmddyy10.;
cards;
111 02/14/2010
222 04/20/2006
333 03/14/2010
; run;
data Av/view=Av;
set A; by id;
if first.id then CLUSTER=1; else CLUSTER+1;
run;
%let maxc=3 ; *>=ma |
|
h*********1 发帖数: 102 | 7 data A;
input id dt1: mmddyy10.;
format dt1 mmddyy10.;
datalines;
1 4/4/2000
1 4/7/2005
1 9/2/2002
2 3/1/2003
2 2/3/2006
3 5/5/2009;
run;
data B;
input id dt2: mmddyy10.;
format dt2 mmddyy10.;
datalines;
1 5/1/1999
1 1/1/2007
2 9/8/2002
2 10/1/2002
2 1/2/2006;
run;
proc sql;
create table C as
select A.*, B.dt2
from A
left join B
on A.id=B.id and
(A.dt1 ge B.dt2 ge mdy(month(A.dt1),day(A.dt1),year(A.dt1)-1));
quit; |
|
d**m 发帖数: 42 | 8 一个quiz的题不会,想请教大家一下,先多谢大家了!
The dataset below contains enrollment records for students. Write code to
count the number of days each student was enrolled. Include both the start
date and the end date in the count. Beware of overlapping date ranges. As an
example student 1’s count should be 6.
data Enrollment;
informat Start_Date MMDDYY10. End_Date MMDDYY10.;
format Start_Date MMDDYY10. End_Date MMDDYY10.;
infile datalines dlm=',';
input Student_Id Start_Date End_Date;
... 阅读全帖 |
|
k*****u 发帖数: 1688 | 9 data test1;
input id date mmddyy10.;
cards;
01 1/2/1999
01 2/2/1999
02 3/3/1999
03 4/3/2000
;
run;
data test2;
input id date2 mmddyy10.;
cards;
01 12/2/1998
02 3/4/2000
03 3/3/1993
;
run;
data new;
merge test1 test2;
by id;
run;
data new1 (keep = id date);
set new;
where date
format date mmddyy10.;
run; |
|
h********o 发帖数: 103 | 10 CHAR变量 is your original variable.
SCAN(string,1,delimiter) is the Nth sub-string delimited by delimiter.
SCAN("01\21\2001",1,"") = 01
SCAN("01\21\2001",2,"") = 21
SCAN("01\21\2001",2,"") = 2001
The full code look like this
================================
DATA OLD;
INPUT CHAR : $10.;
CARDS;
3\3\1996
10\4\2006
10\20\2006
4\15\1997
13\15\1996
11789
;
DATA GOOD BAD(DROP = DATE);
SET OLD;
IF INDEX(CHAR,"") THEN DO;
MONTH = INPUT(SCAN(CHAR, 1, ""),$2.);
DAY = INPUT(SCAN(... 阅读全帖 |
|
l*******0 发帖数: 12 | 11 Can easily be done with any programming.
Here are SAS Codes.
DATA ad (DROP = StartDate EndDate i TotalAmt);
INFILE DATALINES DLM = ",";
INPUT WEB : $20. StartDate : mmddyy10. EndDate : mmddyy10. TotalAmt
DailyAmt;
DO i = 0 TO (EndDate - StartDate);
DATE = StartDate + i;
OUTPUT;
END;
DATALINES;
abc.com, 4/1/2012, 4/30/2012, 30000, 1000
esbn.com, 3/1/2012, 3/15/2012, 10000, 666.67
answer.com, 7/1/2012, 8/1/2012, 50000, 1612.9
;
RUN;
PROC SORT DATA =ad OUT = ad_sorted;
BY DATE;
RUN;
PROC PRI... 阅读全帖 |
|
t******u 发帖数: 345 | 12 每次转换variable的format 和 informat都特别痛苦,尤其是日期相关的情况,一直不
太懂怎么最有效的转换。想了几种常见的情况,哪位高手能帮忙总结一下,除了code,
最好能再解释几句。多谢!多谢!
Variable Original Wanted Sample
Solution
# Name informat informat value
code
1 zip best6. $5. 37000
00237 new_zip = put (zip, $5.);
2 usage $8. 8.2 1234... 阅读全帖 |
|
z**l 发帖数: 82 | 13 请求帮助,我有一个问题。我想保留每个ID 每月销售最低的那条记录,输出的数据就
象data b.
多谢!
data a;
input id date sale;
attrib date informat= mmddyy10. format=mmddyy10.;
cards;
1 08/01/2007 3400
1 07/02/2007 2300
1 08/08/2007 6400
1 02/12/2007 1300
2 04/11/2007 2500
2 05/09/2007 7300
2 06/28/2007 400
2 06/10/2007 1900
3 03/11/2007 6200
3 01/06/2007 5400
3 10/24/2007 5100
3 03/11/2007 1200
;
run;
proc print data=a;
run;
data b:
1 02/12/2007 1300
1 07/02/2007 2300
1 08/01/2007 3400
2 04/11/2007 2500
2 |
|
c**********n 发帖数: 80 | 14 谢谢~
对于第二个问题,我想把日期比如1/10/1960变成sas date:10
我的做法是直接input date mmddyy10. 但是说mmddyy10.的format找不到。mmddyyyy10
. 和mmddyyyy8.也是一样。
这种情况下怎么解决呢?BTW,yyyymmdd10. 不行。
我的数据是:
symbol date volume
symbol_1 10/12/1999 98
symbol_2 11/2/1999 2
symbol_3 6/15/1998 40
要求把date转换成sas date
log 如下:
1 data qqq;
2 set 'd:\sas\mysaslib\qp\arg';
3 input symbol $ volume;
4 run;
ERROR: No DATALINES or INFILE statement.
NOTE: The SAS System stopped processing this step be |
|
k*******a 发帖数: 772 | 15 不知道这个可不可以,你这里只有一个patient啊
data a;
input id visit MMDDYY10. status;
format visit MMDDYY10.;
datalines;
1 1/20/2011 1
1 1/23/2011 1
1 1/25/2011 2
1 1/28/2011 1
1 1/30/2011 1
1 2/13/2011 2
1 2/16/2011 2
1 2/20/2011 2
1 2/25/2011 1
;
proc print data=a;run;
data b(drop=out2);
set a;
by id;
retain out2;
if first.id then out2=0;
if out2=0 and status=2 then do;
out2=1;
output;
end;
else if out2=1 and status=1 then do;
out2=0;
output;
end;
proc print ... 阅读全帖 |
|
h********o 发帖数: 103 | 16 It's not good to save DATE values as character in SAS. Actually it is a
numeric variable. you need to use INFORMAT/FORMAT to read/write those data.
For your case, you can use the following code:
=================
data one;
input char1 $ num1 date : mmddyy10. char2 $ num2;
format date mmddyy10.;
cards;
Adriana 21 3/21/2000 MP 7
Nathan 14 3/21/2000 CD 19
;
proc print;
run;
Obs char1 num1 date char2 num2
1 Adriana 21 03/21/2000... 阅读全帖 |
|
a********a 发帖数: 346 | 17 It is easy.
data one;
input ID DATE$ FACILITY_TYPE;
dat=input(date, MMDDYY10.);
format dat MMDDYY10.;
datalines;
1 1/1/2010 0
1 1/2/2010 0
1 1/3/2010 0
1 1/4/2010 1
1 1/5/2010 1
1 1/6/2010 0
1 1/7/2010 0
2 1/1/2010 0
2 1/2/2010 0
2 1/3/2010 1
2 1/4/2010 1
2 1/5/2010 0
2 1/6/2010 1
2 1/7/2010 1
2 1/8/2010 0
2 1/9/2010 0
;
run;
proc sort data=one;
by id dat FACILITY_TYPE;
run;
data t... 阅读全帖 |
|
h********o 发帖数: 103 | 18 OR Try this:
=======================
DATA GOOD BAD;
SET OLD;
IF INDEX(CHAR,"\") THEN DATE = INPUT(CHAR, MMDDYY10.);
ELSE DATE = .;
FORMAT DATE MMDDYY10.;
IF MISSING(DATE) THEN OUTPUT BAD;
ELSE OUTPUT GOOD;
RUN; |
|
h********o 发帖数: 103 | 19 PROC SQL;
CREATE TABLE FINAL AS
SELECT A.ID,
A.EVENT_DATE FORMAT = MMDDYY10.,
CASE
WHEN MAX(B.ADMISSION_DATE) THEN MAX(B.ADMISSION_DATE)
END AS ADMISSION_DATE FORMAT = MMDDYY10.
FROM FILE1 AS A LEFT JOIN FILE2 AS B
ON A.ID = B.ID AND A.EVENT_DATE >= B.ADMISSION_DATE
GROUP BY A.ID, A.EVENT_DATE
ORDER BY ID, EVENT_DATE;
QUIT; |
|
y********0 发帖数: 638 | 20 是用sql,转置一下,取个最小值就成。
data one;
infile datalines;
input id date mmddyy10.;
datalines;
1 08/12/2005
1 09/13/2005
2 01/09/2005
3 01/08/2005
3 01/08/2005
3 02/09/2005
;
proc transpose data=one out=two;
by id;
run;
proc sql;
select id,min(col1,col2,col3) as mdate format=mmddyy10.
from two;
quit; |
|
k******u 发帖数: 250 | 21 数据为csv file
如下:
123,"Harold Wilson",Acct,01/15/1989,$78,123.
128,"Julia Child",Food,08/29/1988,$89,123
007,"James bond",Security,02/01/2000,$82,1000
828,"Roger Doger",Acct,08/15/1999,$39,100
900,"Earl Davenport",Food,09/09/1989,$45,399
906,"James Swindler",Acct,12/21/1978,$78,200
comma是delimiter.
写了程序如下,
data Employ;
infile 'C:employee.txt' dsd;
input ID : $3.
Name : $20.
Depart : $8.
DateHire : mmddyy10.
salary : dollar8.
;
ru... 阅读全帖 |
|
p*****4 发帖数: 366 | 22 24.Given the following raw data records:
Susan*12/29/1970*10
Michael**6
The following output is desired:
Obs employee bdate years
1 Susan 4015 10
2 Michael . 6
Which SAS program correctly reads in the raw data?
答案是:
data employees;
infile‘file specification’ dlm=‘*’ dsd;
input employee $ bdate : mmddyy10. years;
run;
不明白的是为什么mmddyy10.前面一定要加:?
多谢解答! |
|
a*******y 发帖数: 105 | 23 data A;
input records $ 1-50;
cards;
1/1/2011|5000,3/1/2013|8000
1/1/2011|5000,3/1/2011|8000,4/5/2012|3456
;
run;
data B; set A;
count=countw(records, ',');
if count >= 2 then do;
month2=input(scan(scan(records, count, ','),1,'|'), MMDDYY10.);
month1=input(scan(scan(records, count-1, ','),1,'|'), MMDDYY10.);
monthbetween=intck('Month',month1, month2, 'C');
end;
run; |
|
l****u 发帖数: 529 | 24 从数据库版抄来的,用data step 和proc sql 合起来用,还比较简单。但原题在数据
库版只要求用sql,那可是整篇的code.
原题是:数据如下data one;
input id StartDate mmddyy10. EndDate mmddyy10.;
cards;
1 12/2/2011 1/16/2012
1 3/4/2012 3/24/2012
1 4/5/2012 4/26/2012
1 5/14/2012 6/7/2012
1 8/2/2012 8/6/2012
1 8/9/2012 8/20/2012
2 3/5/2012 7/30/2012
2 8/4/2012 9/15/2012
3 6/5/2012 8/20/2012
;run;
对同一个id,要求将enddate和下一个startdate之间interval不超过30的record和并,
需要得到下面的结果:
1 12/2/2011 1/16/2012
1 3/4/2012 6/7/2012
1 8/2/2012 8/20/2012
2 3/5/2012 9/15/2012
3... 阅读全帖 |
|
a*******y 发帖数: 105 | 25 好像不需要no dupkey,不过最开始还是得sort好。
data c; set one;
retain start2;
by id;
if first.id then start2=startdate;
if startdate - lag(enddate) > 30 then start2=startdate;
run;
data d(rename=(start2=StartDate)); set c(drop=startdate);
by id start2;
if last.start2;
run;
proc print data=d;
format startdate mmddyy10. enddate mmddyy10.;
run; |
|
G**S 发帖数: 1108 | 26
The char variable has format 02/06/1985.
I tried to use
newdate=input(olddate,date10.);
input(olddate,mmddyy10.);
but does not work. Anybody has any idea? Thank you. |
|
|
c**********n 发帖数: 80 | 28 我在网上下载的SAS 9.1.3 安装在D盘里,在编写程序的时候用infile 'd:\abc\efg.
sas7bdat' 语句
时log里面总是说文件不存在。(路径没有错);
另外用到mmddyy10. 的format的时候说找不到这个format,是不是少装了一些功能呢?
我目前把sas完全
安装了还是不行,是不是要另外找补丁?能麻烦告知在哪里能下载么?
十分感谢! |
|
|
s*******s 发帖数: 2 | 30 这个应该用MMDDYY10.而不是MMDDYY8. |
|
n*********y 发帖数: 474 | 31 Base50的最后一题:
data test;
input country $8. date mmddyy10.;
cards;
Germany 12/31/2000
France 01/32/2001
;
run;
这个答案说_error_=1,错误在哪呢?
SAS Base123里面的第18,20,57,58(不好意思,我的Base123文件加密了不能复制出
来T_T)
这五道题很困扰,如能解惑不甚感激! |
|
x***u 发帖数: 962 | 32 想把输出SAS variable到一个fixed length flat file,看起来这样:
12/09/2010 Houston TX 77077
10/16/2009 Houston TX 77040
9/18/2009 Katy TX 77450
这个code对吗?多谢!
Put date mmddyy10. $char8. $char3. $char5.; |
|
x***x 发帖数: 3401 | 33 剩下的variable name呢?
Put date mmddyy10. city $char8. state $char3. zip $char5.; |
|
x***u 发帖数: 962 | 34 如果是input的话应该用哪种方法呢?比如说下面这个
Input variables from the following flat file into SAS Data Set,
12/09/2010;Houston; TX; 77077
10/16/2009;Houston; TX; 77040
9/18/2009;Katy; TX; 77450
input date mmddyy10. city $char8. state $char3. zip $char5.;
这样就可以了吗?
多谢多谢! |
|
a********s 发帖数: 188 | 35 suppose your data test.txt is under C:
data test;
infile "c:\test.txt" dlm=";";
input date mmddyy10. city $ state $ zip;
run; |
|
w*******t 发帖数: 928 | 36 data one;
infile cards;
input date $1-12;
format date1 mmddyy10.;
date1=input(compress(date,' .'), date11.);
cards;
09-Aug.-2009
11-Apr.-2009
;
run;
proc sort data=one; by date1; run; |
|
s******y 发帖数: 352 | 37 hope this will get you stated. I assume the data was already sorted by name.
if not, you have to sort it before run the code.
data have;
input name $ date :mmddyy10. ret;
cards;
A 10/11/10 0.5
A 11/11/10 0.8
A 12/11/10 0.9
B 10/11/10 0.7
B 11/11/10 1.0
B 12/11/10 0.8
;
run;
data want;
do _n_=1 by 1 until(last.name);
set have;
by name;
array temp{999};
temp(_n_)=ret;
end;
do _j=1 to _n_;
set have;
do _i=_j to _n_;
all+temp(_i);
end;
ret=all/(_n_-_j+1);
output;
call missing(all);
en |
|
g**a 发帖数: 2129 | 38 data one;
input sche date10.;
format sche mmddyy10.;
datalines;
4-Dec-08
18-Dec-04
13-Sep-07
15-Sep-07
8-May-07
;
run;
proc print data=one;
run;
that code works for me. |
|
g**a 发帖数: 2129 | 39 data one;
input a $ b c mmddyy10.;
datalines;
s1 10 02/16/2010
s1 20 02/10/2010
s1 30 01/16/2010
s1 40 04/16/2010
s1 50 02/21/2010
s1 60 02/28/2010
s1 70 03/16/2010
s2 110 02/16/2010
s2 120 02/10/2010
s2 130 01/16/2010
s2 140 04/16/2010
s2 150 02/21/2010
s2 160 02/12/2010
s2 170 03/16/2010
s2 180 02/06/2010
s2 190 02/08/2010
s3 210 02/16/2010
s3 220 02/10/2010
s3 230 01/16/2010
s3 240 04/16/2010
s3 250 02/21/2010
s3 260 02/19/2010
;
run;
proc sort data=one;
by a c;
run;
proc print data=one;
run; |
|
P****D 发帖数: 11146 | 40 proc sql;
select Id, min(date) as Date format=mmddyy10. from dst
where date ne .
group by ID;
quit; |
|
m*******g 发帖数: 3044 | 41 I got error message
ERROR 85-322: Expecting a format name.
ERROR 76-322: Syntax error, statement will be ignored.
my code:
data sasuser.aso1;
set sasuser.aso;
DOS=input(DOS,mmddyy10,);
run; |
|
m****r 发帖数: 202 | 42 Thank you both.
1.When use input, my problem is the length of the variable (Date "03/03/2010
") since it is substred from other original database. I checked and found
that its length is $92. Probably that's the reason why input(Date, mmddyy10
.) doesn't work here.
2.mdy()function works well here.
Thanks again |
|
a*****3 发帖数: 601 | 43 data mqrlkr;
input mqrlkr :$100.;
mqrN = put(input(mqrlkr, mmddyy.), date9.); datalines;
5/6/60
;
赏个包子怎么样? 我这儿天寒地冻, 住着半个密林的房子 房东还不给开暖气 还让不
让人活了?
2010: ") since it is substred from other original database. I checked and
found : that its length is $92. Probably that's the reason why input(Date,
mmddyy10: .) doesn't work here. |
|
s******r 发帖数: 1524 | 44 what's the length if you use compress()?
2010
mmddyy10 |
|
p*******r 发帖数: 1951 | 45 data yourdata;
input id date mmddyy10. location;
if id = lag(id) and location = lag(location)
then delete;
cards;
1 1/20/2011 2
1 1/20/2011 1
1 1/20/2011 1
1 1/20/2011 2
1 1/20/2011 3
1 1/20/2011 3
1 1/20/2011 1
2 1/22/2011 4
2 1/22/2011 2
2 1/22/2011 1
2 1/22/2011 1
2 1/22/2011 5
2 1/22/2011 5
2 1/22/2011 5
2 1/22/2011 5
2 1/22/2011 6
;
run; |
|
s*********r 发帖数: 909 | 46 newdate=input(date, mmddyy10.) |
|
d******9 发帖数: 404 | 47 Then, try this:
B=input(DATE,mmddyy10.);
If B=. then output Invalid_data;
SAS will detect the invalid Month and Day itself, if invalid, it will give
missing value to B. |
|
h********o 发帖数: 103 | 48 Try this:
========================================
DATA GOOD BAD(DROP = DATE);
SET OLD;
IF INDEX(CHAR,"\") THEN DO;
MONTH = INPUT(SCAN(CHAR, 1, "\"),$2.);
DAY = INPUT(SCAN(CHAR, 2, "\"),$2.);
YEAR = INPUT(SCAN(CHAR, 3, "\"),$4.);
IF 1 > MONTH > 12 OR 1 > DATE > 31 THEN DATE = .;
ELSE DATE = MDY(MONTH,DAY,YEAR);
END;
ELSE DATE = .;
FORMAT DATE MMDDYY10.;
KEEP CHAR DATE;
IF MISSING(DATE) THEN OUTPUT BAD;
ELSE OUTPUT GOOD;
RUN; |
|
s******r 发帖数: 1524 | 49 you need define
'根本不是日期的值'
data test;
length xx $15.;
input xx $15.;
if index(xx,'')>1 then yy=input(xx,mmddyy10.);
else yy=.;
datalines;
3\3\1996
10\4\2006
10\20\2006
4\15\1997
13\15\1996
11\35\1988
11789
;
run; |
|
s*********r 发帖数: 909 | 50 data b c;
set a;
newdate=input(date,mmddyy10.);
if index(date,"/")=0 then output b;
if newdate=. then output c;
run;
*data b will contain invalid date 11789;
*data c will contain invalid date 13/15/1996. |
|