r********e 发帖数: 1686 | 1 instead of using single tab-,using double tab --
eg. var1--result9 |
|
l*****k 发帖数: 587 | 2 thanks, will give it a try |
|
n***p 发帖数: 508 | 3 I thought you can use _all_ in the var statement. |
|
l*****k 发帖数: 587 | 4 Thanks, will give a try... |
|
|
c*******o 发帖数: 8869 | 6 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; |
|
d*******o 发帖数: 493 | 7 试试这个
data one;
input good P1 P2 P3 P4 P5 P6 P7 P8 P9 P10;
if sum(of good-P10)=11 then yes=1;
else yes=0;
cards;
1 1 0 0 1 0 1 1 0 1 0
0 0 0 1 0 1 1 0 1 0 1
1 1 1 1 0 1 1 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1
;
run;
proc sort data=one; by good yes; run;
Proc transpose data=one out=two name=P;
var P1-P10;
by good yes;
run;
Proc Sql ;
create table three as
select good, p, yes,
sum( col1 , col2) as count
from two
order by p, yes
;quit; |
|
f****r 发帖数: 72 | 8 你的表述好像有些不太清楚。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; |
|
A*******s 发帖数: 3942 | 9 oh, 刚发现一点小错误,transpose之后,默认的col1对应的其实是转置后的第二列,
你要改名的是第一列,默认的column name是_Name_ |
|
d*******1 发帖数: 854 | 10 proc sort data=test1; by _name_; run;
data test1;
set test1;
by _name_;
if first._name_ then i++;
_Name_=cats('col_',put(i,$10.));
run;
proc transpose data=test1 out=test2(drop=_Name_);
var col1;
id=_name_;
run;
另外一个问提是所有的numerical都变成char了, 如果原始的变量是 numerical和char
的混合的话, hehe |
|
w*****e 发帖数: 806 | 11 3x a lot, Banzhu....
it really helps..
rotate data--> proc transpose??? |
|
p********a 发帖数: 5352 | 12 long to wide, wide to long
transpose or array |
|
R******d 发帖数: 1436 | 13 有一个sas数据集,有13000行,13000列(实际上就是个square距离矩阵)。我想输出
到一个tab文件。用了proc export,发现行被截断了。读了下输出的code,里面有一个
参数:lrecl=32767。请问如何把这个参数增加到lrecl=32767000(不知道具体多大,
反正挺大的)。直接这么写会报错。
然后我又想了另外一个办法,把这个矩阵转置一下,那么就变成13000*13000列,行就
只有3个数了。想转置好了再输出,应该就没有lrecl的问题了。好比这样:
proc transpose data=distance_matrix out=pair_distance;
var _all_;
by id;
run;
结果巨慢无比,不知道什么时候才能转完全。
大牛支个招吧,多谢了。 |
|
s*r 发帖数: 2757 | 14 下一步的计算是你自己写的程序 还是别人写好的程序
把那个triangle matrix存成三列可能还是比较容易实现的思路
也许不用array, 用proc transpose + by都可以实现 |
|
R******d 发帖数: 1436 | 15 俺就是不知道怎么写啊,给点提示吧。俺试了transpose,太废时间了。
矩阵的结果输出了给另外一个bash的程序做输入。 |
|
R******d 发帖数: 1436 | 16 transpose俺会啊,上面不给了code了么
就是这个有点慢,想知道有没有别的好的方法输出想要的格式 |
|
p*****o 发帖数: 543 | 17 我有一个数据如下:
NAME COURSE SCORE
LEE ENGLISH 1
WANG ENGLISH 2
LIU ENGLISH .
LEE MATH 2
WANG MATH .
LIU MATH 3
我想TRANSPOSE成如下的形式:
NAME ENGLISH MATH
LEE 1 2
WANG 2 .
LIU . 3
好像是挺简单的转置,但是不知道怎么做? |
|
|
p*****o 发帖数: 543 | 19 。。。。。。。我知道PROC TRANSPOSE。。。。不过真没试出来。。。。 |
|
p*****o 发帖数: 543 | 20 proc transpose data=tem1 output=tem2;
id ??
var ??
run |
|
y*m 发帖数: 102 | 21 proc sort data=t;
by name course;
run;
proc transpose data=t out=t1;
by name;
id course;
run; |
|
d*******o 发帖数: 493 | 22 data one;
input id @;
do i=1 to 3;
if i=1 then type='a';
if i=2 then type='b';
if i=3 then type='c';
input response @;
drop i;
output;
end;
cards;
1 0 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 0 0 0
;
run; |
|
n******9 发帖数: 26 | 23 Thank you so much! Baozi gan xie. |
|
S******y 发帖数: 1123 | 24 # in case you would like to do it in Python :-)
in_file = 'C:\\to_tranx.txt'
f = open(in_file, 'r')
print 'id','type', 'response'
for line in f:
xid, xa, xb, xc = line.split()
print xid, 'a', xa
print xid, 'b', xb
print xid, 'c', xc |
|
a********a 发帖数: 346 | 25 I want the following data set tranfer into another data set.
Id pre_status end_status day
1 0 1 0
1 1 2 210
1 2 4 252
I.e. the pre_status 0 in not included, and the day is transposed into two
columns.
I want the data transfer like the following:
Id pre_status end_status start_day, end_day
1 1 2 0 210
1 2 |
|
h******e 发帖数: 1791 | 26 一个繁琐的方法:
data test;
input var1 $ var2 var3;
datalines;
a . 1.1
a 5 .
a 6 .
b 5 0
b 5 0
b 7 .
;
run;
data t1;
set test;
by var1;
if first.var1 then var4 = 1;
else if first.var1 = 0 and last.var1 = 0 then var4 = 2;
else if last.var1 then var4 = 3;
run;
proc transpose data = t1 out = t2;
by var1 var2;
id var4;
var var3;
run;
data t3;
set t2;
if _1 > 0 or _2 >0 or _3 >0 then do;
_1 = 1.1;
_2 = 1.1;
_3 |
|
d*******1 发帖数: 854 | 27 需要transpose 才行:
split<- strsplit(test$Experiment, '_')
msplit<- t(matrix(unlist(split),nrow=4))
test$time<- msplit[,3] |
|
d*******1 发帖数: 854 | 28 SAS seems to be fine with it because the transposed dataset can still be
handled by SAS although its size become greatly expanded (only by process,
do not even try macro with n=50000 loop!). This type of task is very routine
analysis for genomics. Considering the popularity of R in bioinfo, I can
not imagine that R is not suitable for this..... |
|
x*****r 发帖数: 2404 | 29 sql, transpose, import, export ...好像杂七杂八都用得到
我用不来report,都是用data _null_一个一个put出来的。 |
|
A*******s 发帖数: 3942 | 30 google proc transpose, reshape data, long to wide, wide to long |
|
g**a 发帖数: 2129 | 31 For question one, I think the answer is the dataset that is the first in the FROM statement.
For the second question, the only way I can think of is using IML. How could
you do it by transpose? |
|
f*******e 发帖数: 51 | 32 想不出简单的。。。
proc sql noprint;
select name into : varlst separated by " "
from sashelp.vcolumn
where libname="yourlib" and memname="yourfile" and type="char";
quit;
%put &varlst;
proc transpose data=yourfile out=yourfile2;
var &varlst;
run;
data yourfile2;
set yourfile2;
array char _character_ ;
count=0;
do over char; if char =" " then count+1;
end;
keep _name_ count;
run; |
|
A*******s 发帖数: 3942 | 33 我觉得应该是proc transpose再和原数据merge |
|
l***a 发帖数: 12410 | 34 +1
but op didn't explain if type can have duplicate. if it can, then transpose
will have problem as well |
|
z**k 发帖数: 378 | 35 i v no idea about the scalability of SAS, but I guess it can handle really
large dataset.
My understanding is SAS is not using any of the mainstream database system
like oracle, sql server, etc ... it developed it's own relational database,
and thus has lots of nice buildin functions, like transpose and _N_. It's
true SAS do not maintain index (based on my SAS Adv cert guide), but you can
always index tables right before a complicated query. Of course you could beat SAS if you write all code in |
|
p*****o 发帖数: 543 | 36 actually i coded all by myself but just not a easy way...what i really want is to find a easy way....and i do believe there should be some easy way to take care of it.
and following is just one way i tried.....
%macro assign_rand(gvar);
data t1;
set tmp3;
if a = &gvar.;
run;
data tr1;
array x x1-x27 (1 2 3);
seed = 0;
call ranperm(seed, of x1-x3);
run;
proc transpose data=tr1 out=tr2;
run;
data tr3;
a = &gvar.;
set tr2;
keep a col1;
if _NAME_ = "seed" then delete;
run;
data t2;
set tr3;
set t1; |
|
s*r 发帖数: 2757 | 37 貌似到3个:就到顶了
https://svn.r-project.org/R/trunk/doc/manual/R-intro.texi
There are two operators that work with namespaces. The double-colon
operator @code{::} selects definitions from a particular namespace.
In the example above, the transpose function will always be available
as @code{base::t}, because it is defined in the @code{base} package.
Only functions that are exported from the package can be retrieved in
this way.
The triple-colon operator @code{:::} may be seen in a few places in R
code: |
|
h******e 发帖数: 1791 | 38 简单的很,ttest, means, freq, glm, mixed, sql, transpose, report, sort,
format, printto等。 |
|
g********3 发帖数: 123 | 39 偶有个问题:
原来的data是:
A B C D
100 07 1000 40
100 07 1000 40
100 07 1001 30
100 06 1000 10
100 06 1001 0
101 06 1000 20
101 06 1003 70
101 07 1000 0
101 07 1003 0
要变成:
A C D07 D06
100 1000 40 10
100 1001 30 0
101 1000 0 20
101 1003 0 70
请问应该如何转?
谢谢! |
|
l*********s 发帖数: 5409 | 40 don't do this in SAS, it is not trivial. |
|
|
c*****p 发帖数: 51 | 42 有如下数据
Seller Year var1 var2 var3
ABC 2005 0 0 0
ABC 2006 4 0 0
ABC 2007 17 1 1
EFG 2005 32 4 3
EFG 2006 45 8 5
EFG 2007 50 3 12
...
想变成以下格式新数据
Seller var1 var2 var3 var1 var2 var3 var1 var2 var3
ABC 0 0 0 4 0 0 17 1 1
EFG 32 4 3 45 8 5 50 3 1
...
新数据第2列到第4列为2005的var1到var3,第5列到第7列为2006的var1到var3,第8列到
第10列为2007的var1到var3.
我想用transpo |
|
R*********i 发帖数: 7643 | 43 Do you only want the firm names? It can be done in a few steps. I'm not a
good programmer to have all done in one step. :-)
proc sort data=test out=test1;
by firm year;
run;
*-- Method 1---*;
data test2;
set test1;
by firm year;
retain lastyr;
if first.firm then lastyr=year;
else do;
if lastyr+1=year then flag=1;
lastyr=year;
end;
run;
proc sort data=test2 out=tokeep (keep=firm) nodupkey;
by firm;
where flag;
run;
*-- Method 2---*;
proc transpose data = test1 out = ttes |
|
i******r 发帖数: 323 | 44 Hi I have about 15 tabs in the same excel file, I need to read them in one
by one. I can write a simple macro that read them in one at a time, but I
need to call it for 15 times and type in the tab name. Is there any simple
way?
Also i the excel spreadsheet, if the first row is not the column name, but
second or third row is the column names, so I used getnames=No, then how can
I retain the column names?
I used transpose twice to get the variable names, I think there should be
some easier way.
T |
|
c**********5 发帖数: 653 | 45 解决了。谢谢各位热心帮助。
%macro lp(data,var,var2,num);
data &data;set &data;if &var=. then &var=0;run;
proc sort data=&data;by id mon;run;
proc means data=&data n;
var &var;
by id mon;
where &var=1;
output out=&data._att_con n=&var2;
run;
proc sort data=&data._att_con;by id mon;run;
proc transpose data=&data._att_con out=&data._att_con_n (drop=_name_ _label_
) prefix=mon;
by id; ;
id mon;
var &var2;
run;
data &data._att_con_n;
set &data._att_con_n;
array mt{*} mon1-mon12;
do i=1 to dim(mt);
if mt{i}=. th |
|
s*r 发帖数: 2757 | 46 A' means the transpose of A, A^{-1} means the inverse of a square matrix A
considering svd of X=UDV',so we have XV=UD, and X'X=VDDV'
Xb
= X (X'X)^{-1} X'Y
= X (VDDV')^{-1} X'Y
= X V D^{-2}V' X'Y
= UU'Y (this is formula 3.46 of the elements of statistical learning)
= Y (because U'U=I, U'= U^{-1}, so UU'=I) |
|
|
|
o****o 发帖数: 8077 | 49 data test;
do id='a', 'b', 'c';
do day=1 to 100;
sale=ranuni(9796876)*100;
output;
end;
end;
run;
data fmt;
retain fmtname 'cssale' type 'n' hlo 'M';
retain start 1;
do end=10 to 100 by 10;
label=cats(put(end, Z3.),'d');
output;
end;
run;
proc format cntlin=fmt cntlout=fmtchk;
run;
proc means data=test noprint nway;
by id;
class day /mlf exclusive;
format day cssale.;
var ... 阅读全帖 |
|
d*******o 发帖数: 493 | 50 data one;
do i=1 to 9;
do j=1 to 9;
v=i*j;
output;
end;
end;
run;
proc sort data=one; by j;run;
proc transpose data=one out=two(drop=_name_);
var v;
by j;
run; |
|