由买买提看人间百态

topics

全部话题 - 话题: yourdata
1 2 下页 末页 (共2页)
o******6
发帖数: 538
1
☆─────────────────────────────────────☆
qqzj (小车车) 于 (Mon Mar 16 17:39:29 2009) 提到:
again, easiest to understand, not the fastest:
%let N = 5;
proc sort; by companyname; run;
proc rank data = yourdata out=yourdata;
by companyname;
var date;
ranks count;
run;
proc sql;
create table target as
select a.*, b.date as previousdate, b.value as previousvalue
from yourdata a, yourdata b
where a.companyname = b.companyname and
a.count ge b.count and a.count <= b.count + &N
order by a.companyname, a.d
c*******o
发帖数: 8869
2
来自主题: Statistics版 - 请教一个SAS问题
data yourdata;
set yourdata;
if sum of (p1-p10)=10 and good then yes=1;
else yes=0;
run;
proc sort data=yourdata; by good yes; run;
proc transpose data=yourdata out=tyourdata name=p;
by good yes;
var P1-P10;
run;
proc sql noprint;
create table result as
select good, yes, p, count(*) as count
from tyourdata group by good, yes, p
quit;
c*******o
发帖数: 8869
3
如果用SAS的话, 试试这个MACRO:
%macro a;
proc sql;
select min(year) into: min from yourdata;
select count(distinct year) into: n from yourdata;
%do i=1 %to &n;
select count(distinct id) as count_distinct_id,
min(year) as start_year, max(year) as end_year
from yourdata where &min+&i-1<=year<=&min+&i;
%end;
quit;
%mend;
%a;
o****o
发帖数: 8077
4
来自主题: Statistics版 - Help for freq subset
might be this way:
proc sql;
create table new as
select a.*
from yourdata as a
left join (select personid, count(*) as count
from yourdata(keep=personid)
group by personid
) as b
on a.personid=b.personid
where b.count>=3
;
quit;
or a SAS way
proc freq data=yourdata noprint;
table personid/out=_freq_(where=(count>=3)
keep=personid count
q**j
发帖数: 10612
5
this one works for sure.
data yourdata;
x = 1;
weight = 5;
run;
data yourdata;
set yourdata;
do i=1 to weight;
output;
end;
run;
h********o
发帖数: 103
6
来自主题: Statistics版 - SAS code求教
Try this
=================================
proc sql;
create table temp as
select * from yourdata
where not (id in (select distinct id from yourdata where type in ("
Equipment")) and
id in (select distinct id from yourdata where type in ("Supply")))
order by id;
quit;
data temp;
set temp;
by id;
if first.id then index + 1;
run;
proc sql noprint;
select min(index)into : s
from temp;
select max(index) into : e
from temp;
quit;
%macro create_table;
%do i = &s %to &e;... 阅读全帖
s*******e
发帖数: 1385
7
来自主题: Statistics版 - 问SAS code怎么写
proc sort data=yourdata;
by id date;
run;
data temp;
set yourdata;
by id;
if first.id;
run;
or
proc sql;
create table as
select id, min(date) as new_date
from yourdata;
group by id
order by id;
quit;
l****u
发帖数: 529
8
来自主题: Statistics版 - 请问关于交易量的一个SAS编程问题
这个能简单一些?到现在我还没发现逻辑错误
proc sort data=yourdata;
by id date time;
run;
data yourdata;
set yourdata;
lagid=lag10(id);
lagtime=lag10(time);
lagdate=lag10(time);
if id=lagid and date=lagdate and time-lagtime<=60 then do;
indicator='robot';
output;
end;
run;
s******8
发帖数: 102
9
来自主题: Statistics版 - SAS 求助, 一个小问题, 包子答谢
我觉得应Format比较好。先定义一个Format,暂称之为statefmt, 里面每个州对应一个
不同的数字。
proc format;
value statefmt
alabama='1'
alaska='2'
...
vermont='50';
run;
data two;
set yourdata;
new_var=put(lowcase(state),statefmt.);
run;
或者用macro对每个不同的state值定义一个代码:
%macro s;
proc sql;
select distinct strip(upcase(state)) into: allstates separated by '|'
from yourdata;
%let ns=&sqlobs;
quit;
data two;
set yourdata;
select(strip(upcase(state));
%do i=1 %to &ns;
%let s=%scan(&allstates,&i,'|');
when("&s") new_var=&i;
%end;
otherwise;
en... 阅读全帖
a******c
发帖数: 291
10
来自主题: Statistics版 - 问个SAS 问题
试试以下:
proc sort data=yourdata; by ID descending treatment; run;
data yourdata;
set yourdata;
by ID treatment;
if detail=' ' then detail=lag(detail);
run;
s*********e
发帖数: 1051
11
try this one and it is simpler.
proc sql;
create table
two as
select
b.year as min_year,
b.year + 1 as max_year,
count(distinct a.id) as count
from
yourdata as a, yourdata as b
where
a.year <= b.year + 1 and a.year >= b.year
group by
b.year;
quit;
q**j
发帖数: 10612
12
来自主题: Statistics版 - put statement in macro
data yourdata;
fomat finaloutput $300.;
set yourdata;
array whatever {*} yourvar1-yourvarn;
do i = 1 to n;
if whatever(i) satisfies your condition then
finaloutput = finaloutput||whateveryouneed;
end;
if however put finaloutput;
run;
o****o
发帖数: 8077
13
来自主题: Statistics版 - Help for freq subset
sorry , use join, not left join
"sir" is right, you should use having statement in your code in place of 'where'
proc sql;
create table new as
select a.*
from yourdata as a
join (select personid, count(*) as count
from yourdata(keep=personid)
group by personid
) as b
on a.personid=b.personid
where b.count>=3
;
quit;
o****o
发帖数: 8077
14
来自主题: Statistics版 - 菜鸟问个sas得问题,关于分数组
用PROC SURVEYSELECT
或者下面的code
data yourdata;
do id=1 to 4999;
output;
end;
run;
data x1 x2;
set yourdata nobs=ntotal end=eof;
array _k{3} _temporary_;
if _n_=1 then do;
_k[1]=round(ntotal*0.8); _k[2]=ntotal-_k[1]; _k[3]=ntotal;
end;
if ranuni(987655) < _k[1]/_k[3] then do;
k1=_k[1]; k=_k[3]; _k[1]=_k[1]-1; output x1;
end;
else do;
_k[2]=_k[2]-1; output x2;
end;
_k[3] =_k[3]-1;
run;

n*****s
发帖数: 10232
15
来自主题: Statistics版 - 请教一道sas 题
proc sql;
insert into yourdata;
set value=2893.35 weight=9.0868 gender="F";
insert into yourdata;
set value=56.13 weight=26.2171 gender="M";
....
....
注意考虑定义var这些细节
h********o
发帖数: 103
16
来自主题: Statistics版 - 问个SAS问题
Try this:
========================
DATA YOURDATA;
SET YOURDATA;
ARRAY NUMARRAY(*) _NUMERIC_;
ARRAY CHARARRAY(*) $ _CHARACTER_;
DO I = 1 TO DIM(NUMARRAY);
IF MISSING(NUMARRAY(I)) THEN DELETE;
END;
DO J = 1 TO DIM(CHARARRAY);
IF MISSING(CHARARRAY(J)) THEN DELETE;
END;
DROP I J;
RUN;
n**m
发帖数: 156
17
来自主题: Statistics版 - 问个SAS问题
data yourdata;
set yourdata;
if cmiss(of _character_) > 0 or nmiss(of _numeric_) >0 then delete;
run;
h********o
发帖数: 103
18
来自主题: Statistics版 - SAS code求教
proc sql;
create table both as
select * from yourdata
where id in (select distinct id from test where type in ("Equipment")) and
id in (select distinct id from test where type in ("Supply"));
create table uni as
select * from yourdata
where not (id in (select distinct id from test where type in ("Equipment")
) and
id in (select distinct id from test where type in ("Supply")));
quit;
l****u
发帖数: 529
19
来自主题: Statistics版 - 请问关于交易量的一个SAS编程问题
I did not check it
proc sql;
create table a as
select distinct a.investor, 1 as flag
from yourdata as a, yourdata as b
where a.investor=b.investor and a.date=b.date and a.time<=b.time<=a.time+
60
group by a.investor, a.date, a.time
having count(a.investor) >=10;
quit;
s******8
发帖数: 102
20
来自主题: Statistics版 - proc export to Excel: can not read it!
if your SAS is 64bit 9.3, but you MS is 32 bit, you need download 'SAS PC
files server' and install it.
then dbms=exclecs like:
if there is a file ="&outpath.\&outfile..xls then,
proc export data=yourdata
outfile="&outpath.\&outfile..xls" dbms=excelcs replace;
run;
if there is not a file ="&outpath.\&outfile..xls then
proc export data=yourdata
outfile="&outpath.\&outfile..xlsb" dbms=excelcs replace;
run;
l****u
发帖数: 529
21
data yourdata;
set yourdata;
week=substr(put(date-weekday(date)+1,date9.),1,5)||'to'||
substr(put(date+7-weekday(date),date9.),1,5);
run;
s*******e
发帖数: 1385
22
来自主题: Statistics版 - 求助:一个SAS的小问题
%macro test;
proc sql;
select distinct firms into: firmvars separated by ' '
from yourdata;
quit;
%do i=1 %to %sysfunc(countw(&firmvars));
%let firmvar=%scan(&firmvars., &i., ' ');
data &firmvar.;
set yourdata;
where Firms="&firmvar.";
run;
%end;
%mend test;
%test
l****u
发帖数: 529
23
data yourdata;
set yourdata;
do i=1 to count(yourstr,',')+1;
newstring=scan(yourstr,i,',');
output;
end;
run;
s*********e
发帖数: 1051
24
data set1 set2;
set yourdata;
if mod(id, 2) = 0 then output set1;
else output set2;
run;
c*******o
发帖数: 8869
25
来自主题: Statistics版 - 新人报道,兼问SAS data set的问题
the major difference bw SAS and other programming language is that SAS has a
build-in loop for data reading. If you process SAS in the DATA step, SAS
automatically loop through all the data without the need to manually set up
an array and loop.
in your case, if you want to read the value of varname1 from observation 10
into a macro variable, you can do the followings:
data _null_;
set yourdata;
if _n_=10 then call symput('read',varname1);
run;
now the value of varname1(character) is re
k*******d
发帖数: 20
26
来自主题: Statistics版 - 对应STATA的SAS CODE
Try this!
proc genmod data=yourdata;
model y=x/dist=binomial link=log;
run;
q**j
发帖数: 10612
27
来自主题: Statistics版 - 请教一个SAS文件循环生成的小问题
you do not need sql
data year1 year2 ... yearn;
set yourdata;
do yr = 1 to n;
if year = yr then output yeari;
end;
run;
something like this. you need to work out the details.
sql is verstile, but slow in many situations.
q**j
发帖数: 10612
28
来自主题: Statistics版 - 求助:SAS使用问题(读数据)
proc reg datat = yourdata outest = out;
by whatever;
model whatever;
run;
you can play with the "out" data set later.

万多
个m
把结
等等
q**j
发帖数: 10612
29
来自主题: Statistics版 - 求助:SAS使用问题(读数据)
no daniu, but you really need to do some homework yourself. it is not very n
ice to ask these questions w/o any effort made. at least you can read some s
as starter books.
1. to read data, first save data into .csv file and
proc import data = yourdata dlm=",";
run;
2. to merge:
proc sql or merge statement.
3. to transpose:
proc transpose.

they
q**j
发帖数: 10612
30
来自主题: Statistics版 - 请教SAS ODS to Excel
if column:
look at tagattr
proc report data = yourdata nowd;
define money / style(column) = {tagattr =$#,##0};
define percentage / style(column) = {tagattr =0%};
define order / style(column)=[background = Light Orange];
run;
if row:
use compute block and do something similar.
s*********e
发帖数: 1051
31
来自主题: Statistics版 - 怎样得到OBS的值?
ods output position = output;
proc contents data = yourdata varnum;
run;
q**j
发帖数: 10612
32
来自主题: Statistics版 - A SAS question
you are greedy, but greed is good :)
1. get unique group numbers into a table.
proc sort data = yourdata out=group(keep=group) nodupkey;
by group;
run;
2 do a lot of preparation.
data _NULL_;
set group end=lastobs;
name = cats("group",group);
call symput(cats("group",_n_),name);
if _n_ = 1 then
do;
longname= name;
longgroupvalue= '"'||cats(group)||'"';
end;
else
do;
longname=cats(longname)|| " "||cats(name);
longgroupvalue = cats(longgroupvalue)||", "||'"'||cats(group)||'"';
end;
if lastobs then
o******6
发帖数: 538
33
☆─────────────────────────────────────☆
saintland (水云天) 于 (Wed Feb 11 22:23:07 2009) 提到:
我的数据是每个id对应有一个参数A,按照这个参数从小到大排序,。我想把id按照A的
大小分成三组,使每组的id数目相等。怎么用SAS做?
在 proc rank 里,可以用group=3. 但是由于有tied rank,所以每组的id数目并不相等
。请高人指点!
☆─────────────────────────────────────☆
statcompute (statcompute) 于 (Thu Feb 12 20:33:04 2009) 提到:
here is the pseudo code but not tested.
data tmp1;
set yourdata;
random = ranuni(1);
run;
proc sort data = tmp1;
by A random;
run;
data tmp2;
set tmp1;
by A ran
g**r
发帖数: 425
34
来自主题: Statistics版 - 问一个简单的SAS问题,多谢
data d;
set yourdata;
array a _numeric_;
length k $200.;
if _N_=1 then do;
do over a;
k=vname(a);
lt=length(k)
if substr(k,lt-2)="CC" then put k @;
end;
run;
然后把那个LIST从LOG里面考进来就行了。
如果不想拷,把PUT 换成OUTPUT然后用SQL读到MACRO里面
D******n
发帖数: 2836
35
来自主题: Statistics版 - 请教一个SAS数据input的问题
data a1;
infile './yourdata' missover;
length refid $ 32;
input id $ refid $ @;
do while (refid ne ' ');
refid=compress(refid,"/");
if (refid ne ' ') then output;
input refid $ @;
end;
run;
proc print ;run;

,"/"也被读进去了 (比如说 ‘/// NP_00100’)。 怎末该这个code啊?多谢!
D******n
发帖数: 2836
36
来自主题: Statistics版 - 请教一个SAS数据input的问题
这种data还好,其实是用错了工具,data cleaning从来就不是SAS该做的东西。用perl
或者其他编程语言都比较好搞。SAS不是不行,而是思维不能很直接。linux 下面可以这
样搞。
sed -e 's/\///g' yourdata.dat | perl -e 'while() {@a=split(" ",$_);$i
d=shift @a;for (@a) {print "$id $_\n"}}'
o****o
发帖数: 8077
37
来自主题: Statistics版 - SAS问题请教
data new;
set yourdata;
array _n{*} _numeric_;
do j=1 to dim(_n);
if _n[j] in (-444, -555, -666, -999) then _n[j]=.;
end;
run;
f****r
发帖数: 72
38
来自主题: Statistics版 - 请教一个SAS问题
你的表述好像有些不太清楚。Yes如果仅仅由P(i)所决定。那么Yes就是P(i)的值,对吗?
我是个新手,你可以试试下面的程序,看对不对。
proc transpose data = yourdata out = newdata;
by name Good;
var P1 P2 P3 P4 P5 P6 P7 P8 P9 P10;
run;
data one (keep = Good P Yes);
set newdata;
P = _name_;
Yes = COL1;
run;
proc freq data = one;
tables Good*P*Yes / out = two (keep = Good P Yes Count);
run;
D******n
发帖数: 2836
39
dont confine yourself to SAS, sas is not good at handling dirty data set.
this can be done under linux in one line
sed 's/\// /g' yourdata>newdata
and as i said, u dont even need this if u do it in excel.

function!
save
o****o
发帖数: 8077
40
来自主题: Statistics版 - 问个比较具体的算法问题
if all ids are capitalized Char A-to-Z, then it is easy:
*-----------------------;
data yourdata;
input group_id id1 $ ID $;
datalines;
1 A B
1 A C
1 A D
2 B A
2 B C
2 B D
3 C B
4 D A
4 D B
5 B E
5 B K
5 B E
6 B F
7 E K
;
run;
data newdata;
array _C1[65:90] _temporary_;
do i=65 to 90; _C1[i]=0; end;
do until (eof);
d*******o
发帖数: 493
41
proc sgplot data=yourdata;
xaxis type=discrete;
series x=year y=series/group=type;
refline 5 3 2;
run;
D******n
发帖数: 2836
42
assuming your data is sorted by v1:
data _temp_;set yourdata;by v1;retain rownum 0;
if first.v1 then rownum=0;rownum=rownum+1;run;
proc sort ;by v1 descending v3;run;
data _temp_;set _temp_;by v1;if first.v1;drop v2;run;
o****o
发帖数: 8077
43
proc means data=yourdata noprint;
by id;
var medication_:;
output out=newdata(where=(_STAT_='MAX') drop=_TYPE_ _FREQ_) ;
run;
baozi pls...
m**********r
发帖数: 122
44
来自主题: Statistics版 - 关于 data merge
正在看 data merge, 有个例子是这样得
data newdata;
merge yourdata (in=a) otherdata (in=b);
by permno date;
请问这里的(in=a) 和(in=b)是什么意思。
c*******7
发帖数: 2506
45
来自主题: Statistics版 - 关于 data merge
生成两个flag变量,告诉你该记录是来自yourdata (a=1)还是otherdata (b=1)
p*******r
发帖数: 1951
46
来自主题: Statistics版 - Data Manipulation(Help)
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;
o****o
发帖数: 8077
47
proc sql;
create view tempv as
select *
from yourdata(where=(return^=0))
order by id, date
;
quit;
data selected;
set tempv;
by id date;
if first.id;
run;
q**j
发帖数: 10612
48
data youdata;
set yourdata;
do i=1 to weight;
output;
end;
run;
EA
发帖数: 3965
49
来自主题: Statistics版 - 请教一个问题,谢谢。
proc sql;
create table test
as select *, count(distinct class) as y
from yourdata
group by id
;
quit;
l*****8
发帖数: 483
50
来自主题: Statistics版 - 求助sas code
data bb;
set yourdata;
retain count;
if income>expense then count+1;
else count=0;
run;
1 2 下页 末页 (共2页)