由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Faculty版 - SAS question using PROC SQL 高手请进, 包子答谢
相关主题
是不是中国人特别重视学校排名?周末包子谢帖及请教高手
在线等:10包子题目 SAS simultaneous equations quesitons[Solved] Ubuntu 8.10安装在外置USB硬盘的问题
郁闷的求助:有人用SAS做fixed-effect model 或2SLS吗?两个有关于R的小问题?
能在版上求paper review么 signal proc estimation control再问R的问题 - 关于matrix 的operation
SAS question using PROC SQL 高手请进, 包子答谢借人 气问 两个 问题:
更新一下Taste of R,再问两个R的问题。请教一下SAS编程的一个问题
proc sql - SAS 10 包子请教【包子】求percentile问题
一道面试题求解再问一个sas输出的问题 (export)
相关话题的讨论汇总
话题: date1话题: data1话题: date2话题: data2话题: proc
进入Faculty版参与讨论
1 (共1页)
t**********r
发帖数: 182
1
Want to merge two data sets using proc sql:
Data1:
var1 var2 date1
Data2:
var1 var2 date2 rating
(Note: var1 and var2 are the same variables in these two data sets)
Question:
Select rating in data2 to data1; meeting the following criteria:
1. date1 - date2 >0
2. date1 - date2 has the minimum value.
I wrote the following code; but it won't work:
proc sql;
create table data3 as
select data1.*, data2.rating, date1-date1 as diff
from data1, data2
where data1.var1=data2.var1 and data1.var2=data2.var2
m********5
发帖数: 619
2
你这个条件1和条件2我看着怎么重叠啊....
proc sql; create table data3 as select a.*, b.* from data1 as a, data2 as b
where a.var1=b.var1 and a.var2=b.var2 and a.date1-b.date2>=minvalue and a.
date1-b.date2>0;
quit;

【在 t**********r 的大作中提到】
: Want to merge two data sets using proc sql:
: Data1:
: var1 var2 date1
: Data2:
: var1 var2 date2 rating
: (Note: var1 and var2 are the same variables in these two data sets)
: Question:
: Select rating in data2 to data1; meeting the following criteria:
: 1. date1 - date2 >0
: 2. date1 - date2 has the minimum value.

t**********r
发帖数: 182
3
Thank you.
你这个条件1和条件2我看着怎么重叠啊....
No. There are many obs that meet date1 - date2 >0; but I only want the one
with the min value.
S****Y
发帖数: 4634
4
post log

【在 t**********r 的大作中提到】
: Want to merge two data sets using proc sql:
: Data1:
: var1 var2 date1
: Data2:
: var1 var2 date2 rating
: (Note: var1 and var2 are the same variables in these two data sets)
: Question:
: Select rating in data2 to data1; meeting the following criteria:
: 1. date1 - date2 >0
: 2. date1 - date2 has the minimum value.

m********5
发帖数: 619
5
如果你这个min value>0
>0的条件就是多余的
如果你这个min value<0
>min value这个条件就是多余的。。。

【在 t**********r 的大作中提到】
: Thank you.
: 你这个条件1和条件2我看着怎么重叠啊....
: No. There are many obs that meet date1 - date2 >0; but I only want the one
: with the min value.

t**********r
发帖数: 182
6
I tried your code - it does not work...
m********5
发帖数: 619
7
hehe, good luck finding one that works

【在 t**********r 的大作中提到】
: I tried your code - it does not work...
t**********r
发帖数: 182
8
This min value is changing for different observations..

【在 m********5 的大作中提到】
: 如果你这个min value>0
: >0的条件就是多余的
: 如果你这个min value<0
: >min value这个条件就是多余的。。。

m********5
发帖数: 619
9
你以为proc sql是机器人啊
你既然有dataset 3 containing a variable (minvalue)
你不告诉sas,sas怎么算

【在 t**********r 的大作中提到】
: This min value is changing for different observations..
t**********r
发帖数: 182
10
ERROR: The following columns were not found in the contributing tables: diff.
516 having diff=min(diff);
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

【在 S****Y 的大作中提到】
: post log
S****Y
发帖数: 4634
11
先把having前面的";"删了

diff.

【在 t**********r 的大作中提到】
: ERROR: The following columns were not found in the contributing tables: diff.
: 516 having diff=min(diff);
: ------
: 180
: ERROR 180-322: Statement is not valid or it is used out of proper order.

t**********r
发帖数: 182
12
Many thanks for your hint!! I made it. Here is the code.
579 proc sql;
580 create table data3 as
581 select data1.*, data2.rating, day1-day2 as diff
582 from data1, data2
583 where data1.var1=data2.var1 and data1.var2=data2.var2
584 and date1-date2>0
585 group by data1.var1, data1.var2, data1.date1
586 having diff=min(diff);
NOTE: The query requires remerging summary statistics back with the original
data.
NOTE: Table WORK.data3 created, with 48144 rows and 9
t**********r
发帖数: 182
13
10 baozi has been sent. Thanks.

【在 m********5 的大作中提到】
: 你以为proc sql是机器人啊
: 你既然有dataset 3 containing a variable (minvalue)
: 你不告诉sas,sas怎么算

t**********r
发帖数: 182
14
10 baozi has been sent. thanks.

【在 S****Y 的大作中提到】
: 先把having前面的";"删了
:
: diff.

1 (共1页)
进入Faculty版参与讨论
相关主题
再问一个sas输出的问题 (export)SAS question using PROC SQL 高手请进, 包子答谢
大家练练手吧,挺有意思的一道题更新一下Taste of R,再问两个R的问题。
SAS应用问题proc sql - SAS 10 包子请教
请教一个用SAS作DATA MERGE的问题一道面试题求解
是不是中国人特别重视学校排名?周末包子谢帖及请教高手
在线等:10包子题目 SAS simultaneous equations quesitons[Solved] Ubuntu 8.10安装在外置USB硬盘的问题
郁闷的求助:有人用SAS做fixed-effect model 或2SLS吗?两个有关于R的小问题?
能在版上求paper review么 signal proc estimation control再问R的问题 - 关于matrix 的operation
相关话题的讨论汇总
话题: date1话题: data1话题: date2话题: data2话题: proc