|
s******r 发帖数: 1524 | 2 If for sure you only one record, use
proc sql;
select date,
max(case when group ='M' then credit1 else . end) as credit1_m,
max(case when group ='M' then credit2 else . end) as credit2_m,
....
from
group by date;
quit;run; |
|
d**********2 发帖数: 14 | 3 Hi,
I have a data which contains only one variable, the value of which is either
1 or 2, so that the data looks like this, 1221111222221221222 (of course
this is what it looks like after I transposed it). Now I need to know how I
could calculate the number of times 1 and 2 appeared CONSECUTIVELY, for
example, in this case, 1 made a single appearance for 3 times and made a
quadraple appearance for once, 2 made a double appearance for twice, a
triple appearance for once and a 5-times-in-a-row appe... 阅读全帖 |
|
d******e 发帖数: 551 | 4 准备几个经典的呗,什么是p-value;response,比如说fraud要用什么model(
logistic);怎么处理missing value,怎么处理outliner,怎么做model selection,
什么是multi collinarity (这个拼得不对,自己查查)
SAS编程最容易问的问题:简单的SQL,left join跟right join, outer join 都有什么
区别;什么是retain;proc transpose怎么用;复杂的模型怎么求数值解。macro基本
的会,扯扯就好了,又不是找SAS programmer哪有问那么深的。真要招SAS programmer
,也没什么意思不用去了。 |
|
y****n 发帖数: 46 | 5 data have;
input id $ num;
cards;
A 1
A 2
A 3
A 4
B 1
B 2
B 3
B 4
;
run;
proc sort data=have;
by num id;
run;
proc transpose data=have out=want(drop=_name_ num);
by num notsorted;
var num;
id id;
run; |
|
d*******o 发帖数: 493 | 6 data have;
infile datalines dlm = ',';
retain row;
input myvar $ @@ ;
if prxmatch("/10\d/", myvar) ne 0 then row +1;
if missing(myvar) then delete;
datalines;
100, Grace, 3,1,5,2,6
101, Martin, 1,2,4
102, Scott, 9,10,4,
5, 6
103, Bob,2 ,1, 2, 2,4
;
run;
proc transpose data=have out=want(drop = row _name_);
by row;
var myvar;
run; |
|
d*******o 发帖数: 493 | 7 data have;
input
SCHOOLID;
idx = _n_;
cards;
1
1
5
6
10
10
10
11
;
run;
proc transpose data = have out = _tmp prefix = school_;
by idx;
var schoolid;
id schoolid;
run;
data want;
set _tmp;
array a[*] s:;
do i = 1 to dim(a);
if missing(a[i]) = 0 then a[i] = 1;
else a[i] = 0;
end;
keep s:;
run; |
|
y****n 发帖数: 46 | 8 change dapangmao's code to following:
data have;
input
xx;
idx = _n_;
SCHOOLID=xx;
cards;
1
1
5
6
10
10
10
11
;
run;
proc transpose data = have out = _tmp(drop=_name_ idx) prefix = school_;
by idx schoolid;
var xx;
id xx;
run;
data want;
set _tmp;
array a[*] school_:;
do i = 1 to dim(a);
if missing(a[i]) = 0 then a[i] = 1;
else a[i] = 0;
end;
keep s:;
run; |
|
|
c*******o 发帖数: 3829 | 10 proc transpose data=youdata out=two(rename=(_Name_=Type col1=Amount));
by Date SeriesNO;
run;
data three;
set two;
where Amount ne .;
Type=substr(Type,5);
run; |
|
d********h 发帖数: 2048 | 11 proc transpose data=test out=test1;
var feature;
by id;
data test2;
length c $ 1000;
set test1 ;
array tmp col1-col3;
do over tmp;
c=catx("_",of c tmp);
end;
proc print; |
|
k*******a 发帖数: 772 | 12 可以用transpose,不过可能得先建立一些新的变量 |
|
|
h********o 发帖数: 103 | 14 DATA ONE;
INPUT VAR $ @@;
CARDS;
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14
;
DATA ONE;
SET ONE;
RETAIN ID ;
IF MOD(_N_, 5) = 1 THEN ID + 1;
RUN;
PROC TRANSPOSE DATA = ONE OUT = TWO (DROP = _NAME_ ID
RENAME = (COL1 = VAR1
COL2 = VAR2
COL3 = VAR3
COL4 = VAR4
C... 阅读全帖 |
|
h********o 发帖数: 103 | 15 This one is more clean.
=================
DATA ONE;
INPUT VAR $ @@;
CARDS;
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14
;
DATA ONE;
SET ONE;
IF MOD(_N_, 5) = 1 THEN ID + 1;
RUN;
PROC TRANSPOSE DATA = ONE OUT = TWO (DROP = _NAME_ ID) PREFIX = VAR;
VAR VAR;
BY ID;
RUN; |
|
p***r 发帖数: 920 | 16 try my version, without transpose
DATA ONE;
INPUT VAR $ @@;
CARDS;
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14
;
data two;
set one;
id= int((_n_-1)/5);
length v1-v5 $10.;
if mod(_n_,5)=1 then do;
v1='';
v2='';
v3='';
v4='';
v5='';
end;
if mod(_n_,5)=1 then v1=var;
if mod(_n_,5)=2 then v2=var;
if mod(_n_,5)=3 then v3=var;
if mod(_n_,5)=4 then v4=var;
if mod(_n_,5)=0 then v5=var;
if mod(_n_,5) ne 0 then
do;
retain v1 v2 v3 v4 v5;
end;
drop var;
run;
proc sort data=two ;
by id descending v... 阅读全帖 |
|
o****o 发帖数: 8077 | 17 data old;
do x=1 to 100;
output;
end;
run;
*****************************************************
1:
data oldv/view=oldv;
set old;
id=mod(_n_-1, 5)+1;
group=floor((_n_-1)/5);
run;
proc transpose data=oldv out=new name=id prefix=a;
by group;
var x;
id id;
run;
******************************************************
2:
%let itv=5;
%let oldvar=x;
data new;
set old;
array a{&itv};
retain a1-a&itv;
j=mod(_n_-1, &itv)+1;
if j=1 then do k=1 to ... 阅读全帖 |
|
l*********s 发帖数: 5409 | 18 a stupid solution, transpose then nmiss function |
|
D******n 发帖数: 2836 | 19 ya, i remember your method, it works great for character variables.
I just figured out that for numeric variables, proc means + transpose
can do the work and it is much simpler.
For character variables, i am still thinking if there is a simpler way
than yours...lol
vars,
elements
to |
|
|
m****r 发帖数: 202 | 21 Thanks. Could you please give me more detail?
My variable names are AS01d,AS01m,AS01y,AS02a,AS02b,AS02c,AS02_age.
I transposed them to observations, but still don't know how to add "_30" to
them.
Thanks a lot |
|
m****r 发帖数: 202 | 22 proc contents data=old
out=try(keep=varnum name)
noprint;
run;
data new (keep=newname varnum);
set try;
do i=1 to 1500;
if varnum=(i)
then newname=compress(name)||"_30";
end;
run;
proc transpose data=new
out=aa30d(drop=i _name_);
id newname;
run;
The problem here is some original cha variables have been changed to num
ones. This is not exactly I expect. |
|
R*********i 发帖数: 7643 | 23 1) proc sql, the easiest way;
2) sort by ID, year and use by & retain to count # of years each ID has,
output to a list dataset, then merge back to the orginal and only keep those
from the list;
3) proc transpose year variable by ID, use array to find the IDs w. all five
years to generate a list and merge back to original keeping IDs from the
list. |
|
o****o 发帖数: 8077 | 24 why do u have to transpose the data twice? you can simply do:
data test3;
merge test(where=(group='A') rename=(X=A))
test(where=(group='B') rename=(X=B))
;
run; |
|
s*********r 发帖数: 909 | 25 proc transpose data=old out=new(drop=_name_) prefix=id_;
by group;
var id;
run; |
|
d******9 发帖数: 404 | 26 You can use Proc Transpose or Array to do it.Here is the array method.
Proc sort data=Old ;
By Group;
Run;
Data New;
Set Old;
By group;
Array ID(n) $ V1-Vn; --- n is the max number of distinct ID in a group.
Retain V1-Vn;
Keep group V1-Vn;
If first.group then do I=1 to n;
CNT=0;
ID(I)=.;
End;
CNT+1;
ID(CNT)=ID;
If last.group;
Run; |
|
s*********r 发帖数: 909 | 27 发信人: papertigra (长工胖头猪), 信区: Statistics
标 题: CRO SAS Interview questions
发信站: BBS 未名空间站 (Fri Feb 26 21:12:00 2010, 美东)
http://www.sas9.blogspot.com/
SAS Programer Position
1. What kind of AE tables are there?
2. What difference between proc means and freq?
3. What does run statement mean?
4. What is ITT? What assessment in ITT definition is?
5. Which procedure can produce standard deviation of a variable?
6. What do put and input functions do?
7. How to validate your program?
8. How to identify... 阅读全帖 |
|
k*******y 发帖数: 132 | 28 1. rp is important, no rp no reference...
2. be easy-going and confident
3. be familiar with base SAS(little sas book is not enough)
frequently asked questions:
proc univariate/means/transpose/report/tabulate/
set/in=/merge/array/retain/substr/translate
ods system/
index/sql
questions about large dataset
4. be familiar with the models you write on your resume |
|
k*******a 发帖数: 772 | 29 data a;
input ID A B C;
datalines;
1 1 0 1
2 0 1 0
3 . 1 0
4 0 1 .
5 . . 0
;
run;
proc transpose data=a out=b;
by id;
var a b c;
run;
proc freq data=b;
table col1*_name_;
run; |
|
d******9 发帖数: 404 | 30 We can also use data step to do it, without transpose:
Data B (drop=ID A B C);
Set A End=EOF;
If A=1 then A_1 +1;
Else if A=0 then A_0 +1;
If B=1 then B_1 +1;
Else if B=0 then B_0 +1;
If C=1 then C_1 +1;
Else if C=0 then C_0 +1;
If EOF=1 then output;
Run; |
|
s******n 发帖数: 42 | 31 哇,大牛出手相助,拜谢拜谢
问题比我想象的复杂,我以为用点排序和条件语句就可以了
btw, sql有没有方便的方式将行和列调换,就像excel里paste special-transpose那种
效果的? |
|
|
n**m 发帖数: 156 | 33 汇报一下,我最后把几个dataset transpose成一个row的observation。然后拼起来进
行计算。因为最多的也就两行,所以不算麻烦。
r是好,但是主要是想重复使用时,用起来方便一点,所以r不考虑了。 |
|
k*******a 发帖数: 772 | 34 sql似乎也不容易把,不过可以试试 proc transpose |
|
|
|
d******9 发帖数: 404 | 37 Good. Macro is also a solution to it.
Now we have 3 methods: Proc Transpose, Array, Macro.
Any other methods? |
|
o*******w 发帖数: 2310 | 38 proc transpose then use if to group the value |
|
l*********s 发帖数: 5409 | 39 I am having some very weird bug while trying to write a macro that can
expend the short hand notion like var1--var11 used in SAS.
The "shorthand" macro works fine on its own, but fails to work when called
by the "formula" macro. The error message seems to say that "the set
statement in the data step is not valid or not in proper order", what's
going on?
Many thanks!
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////... 阅读全帖 |
|
a***d 发帖数: 336 | 40 来自主题: Statistics版 - sas问题 proc sql noprint;
create table tmp as
select count(distinct c) as count
from table
group by a, b;
quit;
proc sort data tmp;
by a;
run;
proc transpose data=tmp;
by a;
id b;
var count;
run;
数。 |
|
o****o 发帖数: 8077 | 41 也许可以试试PROC STDIZE
data a1;
input x_1 y z weight;
datalines;
1 0 4 0.1
1 0 4 0.5
0 1 1 0.2
0 1 1 0.2
1 0 2 0.1
0 1 2 0.5
1 0 3 0.2
0 1 3 0.2
;
run;
ods select none;
proc stdize data=a1 out=_null_ outstat=stat pctlpts=0 100;
var x_1 y z ;
weight weight;
run;
ods select all;
proc transpose data=stat out=stat2 ;
id _type_;
run;
痛。 |
|
D**g 发帖数: 739 | 42 I guess you'd better think about how to interpret the results first before
you run the model if you have many time varying things. For example, it
may be ok to run a model with data set as what you transposed, but the
interpretation will be very difficult. You may need to simplify your
analysis. You can read Don Hedecker's book or check his website. http://www.uic.edu/classes/bstt/bstt513/index.html |
|
a****t 发帖数: 1007 | 43 proc transpose ...
...
by department id;
quit;
这个应该可以解决问题,但是晚了,包子没了。 :( |
|
k****i 发帖数: 347 | 44 如果data在long format下是每个人有多行observation,但是# of obs并不固定
比如第一个人50行,第二个人33行,第三个人42行。。。
variable数目很大(>100),x1, x2, x3 ...
这种情况下想转换成wide format,也就是每人只有一行,但是variable要transpose成
x1_1, x1_2, x1_3, ... x1_n, x2_1, x2_2, x2_3, ... x2_n, x3_1, x3_2, x3_3, ..
. x3_n
似乎一般的data step long to wide format办法不行(因为每个人# of obs不固定会
导致out of range error?)
求可运行的sas macro/code |
|
k*******a 发帖数: 772 | 45 可以对每个variable单独做transpose,然后把他们merge起来?可以用macro |
|
a*****3 发帖数: 601 | 46 很奇怪, 用一般的proc transpose 不能实现吗?
没看懂为什么产生那个out of range错误 。 |
|
j*****g 发帖数: 222 | 47 二流学校统计master毕业,3年做了四份工作,电面50+,onsite 10家, onsite 成功率
算7.5吧(0.5是有一家,老板很喜欢我,但是怕我干不长就跑了,面试之后还打电话给
我,要我表决心,那个时候我已经拿到一个更喜欢的offer了,于是不了了之), 大部
分都是marketing research方面的职位,因为比较感兴趣
总结一下经常问到的技术问题吧, 这些问题我觉得marketing research方向的话,基
本是必问的,其实都很简单,但是想到了还是列一下,ms列的有点乱
SAS
(1) Proc transpose
(2) Merge data的时候要注意什么问题?
a. Have to sort both tables before merging
b. Check what’s the type of merge (one to many, one to one, or many to
many?) --- check duplicates in each table (这条很多经验不够的通常都想不到
,只想到sort)
c. ... 阅读全帖 |
|
i***m 发帖数: 148 | 48 很好的经验,然后我加一些自己的经验供大家讨论
SAS
(1) Proc transpose
(2) Merge data的时候要注意什么问题?
a. Have to sort both tables before merging
b. Check what’s the type of merge (one to many, one to one, or many to
many?) --- check duplicates in each table (这条很多经验不够的通常都想不到
,只想到sort)
c. What if you only want to keep the IDs in table a?
--many to many merge, data step 与sql的不同
--missing data在merge时的处理,尤其是primary key有missing时
(3) Array
If you have a data set a with 1000 columns, you want to change all the
mi... 阅读全帖 |
|
r*********o 发帖数: 490 | 49 你是说把data transpose吗,那样怎么做ttest啊 |
|
h**h 发帖数: 488 | 50 我现在有个这样的data set
ID Class Cost
1 A $10
1 B $20
1 C $30
2 A $10
2 C $30
2 D $40
3 A $10
3 B $20
3 C $30
3 D $40
4 B $20
4 E $50
要转化成这样的格式
ID A B C D E
1 $10 $20 $30
2 $10 $30 $40
3 $10 $20 $30 $40
4 $20 $50
实际上class比较多,有的ID占很多,有的ID只占一个。想列成这样的格式让cost直观显示。怎么做呢。尝试了proc transpose不行。 |
|