SAS 数据组织
SAS Data organization
我有像附图一样的数据集,我只想要每年具有相同 numsecur 的观测值。
如何在 SAS proc sql 函数中执行此操作?这在 STATA 中会更容易吗?如果可以,我可以使用什么程序?
您看起来像是 Whosebug 的新用户。欢迎。您的问题被否决至少出于三个原因:
1) It's not really clear what you want from your description of the problem and the data
you're providing
2) You haven't shown any attempts at what you've tried
3) Providing your data as a picture is not great. It's most helpful if you're going
to provide data to provide it so it's easy for others to consume in their program.
After all, you're asking for our help make it easier for us to help you. If You
included something like the following we just have to copy and paste to create your
dataset to work with:
DATA test;
INPUT ID YEAR EXEC SUM;
DATALINES;
1573 1997 50 1080
1581 1997 51 300
1598 1996 54 80
1598 1998 54 80
1598 1999 54 80
1602 1996 55 112.6
1602 1997 55 335.965
;
RUN;
话虽这么说,但以下内容可能会为您提供所需的内容,但这只是一个猜测,因为我不确定这是否真的是您要问的:
proc sql no print;
create table testout as
select *,count(*) as cnt
from test
group by sum
having cnt > 1;
quit;
您是在问:显示所有使用相同 SUM 的行还是其他?
假设我正确理解了您的问题,您希望仅当公司每年都有相同的 numsecur 时才保持相同的观察结果 company/individual。所以,这是我会尝试使用 STATA 的方法:
input ID YEAR EXEC SUM
1573 1997 50 1080 //
1581 1997 51 300 //
1598 1996 54 80 //
1598 1998 54 80 //
1598 1999 54 80 //
1602 1996 55 112.6 //
1602 1997 55 335.965 //
1575 1997 50 1080 //
1575 1998 51 1080 //
1595 1996 54 80 //
1595 1998 54 30 //
1595 1999 54 80 //
1605 1996 55 112.6 //
1605 1997 55 335.965 //
end
bysort ID SUM: gen drop=cond(_N==1, 0,_n)
drop if drop==0
结果显示(根据我的数据):
ID YEAR EXEC SUM drop
1. 1575 1997 50 1080 1
2. 1575 1998 51 1080 2
3. 1595 1999 54 80 1
4. 1595 1996 54 80 2
5. 1598 1996 54 80 1
6. 1598 1998 54 80 2
7. 1598 1999 54 80 3
我有像附图一样的数据集,我只想要每年具有相同 numsecur 的观测值。
如何在 SAS proc sql 函数中执行此操作?这在 STATA 中会更容易吗?如果可以,我可以使用什么程序?
您看起来像是 Whosebug 的新用户。欢迎。您的问题被否决至少出于三个原因:
1) It's not really clear what you want from your description of the problem and the data
you're providing
2) You haven't shown any attempts at what you've tried
3) Providing your data as a picture is not great. It's most helpful if you're going
to provide data to provide it so it's easy for others to consume in their program.
After all, you're asking for our help make it easier for us to help you. If You
included something like the following we just have to copy and paste to create your
dataset to work with:
DATA test;
INPUT ID YEAR EXEC SUM;
DATALINES;
1573 1997 50 1080
1581 1997 51 300
1598 1996 54 80
1598 1998 54 80
1598 1999 54 80
1602 1996 55 112.6
1602 1997 55 335.965
;
RUN;
话虽这么说,但以下内容可能会为您提供所需的内容,但这只是一个猜测,因为我不确定这是否真的是您要问的:
proc sql no print;
create table testout as
select *,count(*) as cnt
from test
group by sum
having cnt > 1;
quit;
您是在问:显示所有使用相同 SUM 的行还是其他?
假设我正确理解了您的问题,您希望仅当公司每年都有相同的 numsecur 时才保持相同的观察结果 company/individual。所以,这是我会尝试使用 STATA 的方法:
input ID YEAR EXEC SUM
1573 1997 50 1080 //
1581 1997 51 300 //
1598 1996 54 80 //
1598 1998 54 80 //
1598 1999 54 80 //
1602 1996 55 112.6 //
1602 1997 55 335.965 //
1575 1997 50 1080 //
1575 1998 51 1080 //
1595 1996 54 80 //
1595 1998 54 30 //
1595 1999 54 80 //
1605 1996 55 112.6 //
1605 1997 55 335.965 //
end
bysort ID SUM: gen drop=cond(_N==1, 0,_n)
drop if drop==0
结果显示(根据我的数据):
ID YEAR EXEC SUM drop 1. 1575 1997 50 1080 1 2. 1575 1998 51 1080 2 3. 1595 1999 54 80 1 4. 1595 1996 54 80 2 5. 1598 1996 54 80 1 6. 1598 1998 54 80 2 7. 1598 1999 54 80 3