y******n 发帖数: 188 | 1 如图,在只是知道第一列(obs)数据的情况下,
如何加入第二列变量group,并且赋值
谢谢 |
l*********s 发帖数: 5409 | 2 make a counter variable which is increased whenever you see a 1, then
translate it into letters. |
h********o 发帖数: 103 | 3 Try this:
==========================
DATA TEST;
INPUT OBS @@;
CARDS;
1 2 3 1 2 3 4 5 1 2 1 2 3 4 1 2 3 4 5 6 7 8 9
;
DATA TEST (DROP = CHAR INDEX);
CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SET TEST;
IF OBS = 1 THEN INDEX + 1;
GROUP = SUBSTR(CHAR,INDEX,1);
RUN; |
y******n 发帖数: 188 | 4 This works.
Thank you very much!
【在 h********o 的大作中提到】 : Try this: : ========================== : DATA TEST; : INPUT OBS @@; : CARDS; : 1 2 3 1 2 3 4 5 1 2 1 2 3 4 1 2 3 4 5 6 7 8 9 : ; : DATA TEST (DROP = CHAR INDEX); : CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; : SET TEST;
|
y******n 发帖数: 188 | 5 proc sql;
create table temp as
select group, max(obs) as numObs
from test
group by group;
quit;
SAS give the note:
“The query requires remerging summary statistics back with the original
data”
How to solve this problem?
Thanks a lot! |
h********o 发帖数: 103 | 6 I don't see any problem with your codes and it works fine with the following
SAS LOG notes:
===================================
41 proc sql;
42 create table temp as
43 select group, max(obs) as numObs
44 from test
45 group by group;
NOTE: Table WORK.TEMP created, with 5 rows and 2 columns.
46 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds |
h********o 发帖数: 103 | 7 The better way:
=========================
DATA TEST ;
SET TEST;
IF OBS = 1 THEN INDEX + 1;
GROUP = BYTE(INDEX + 64);
DROP INDEX;
RUN; |