SAS代码用于根据一个主题识别多行中的不同数值。

huangapple go评论53阅读模式
英文:

SAS code to identify different values in multiple rows according to one subject

问题

以下是翻译好的部分:

ID CASE VALUE DUMMY 是否具有组合
123 4736 E10 1 1
123 1254 N65 0 1
123 0997 E11 1 1
123 7655 x 0 1
987 1234 x 0 0
987 6376 E10 1 0
987 0980 E18 0 0

提前感谢,

PP

英文:

the following data structure is given:

ID CASE VALUE DUMMY
123 4736 E10 1
123 1254 N65 0
123 0997 E11 1
123 7655 x 0
987 1234 x 0
987 6376 E10 1
987 0980 E18 0

I want to know: How can i create a new variable that includes if someone actually has the combination of E10 AND E11 (0,1) as follows:

ID CASE VALUE DUMMY Has the combination
123 4736 E10 1 1
123 1254 N65 0 1
123 0997 E11 1 1
123 7655 x 0 1
987 1234 x 0 0
987 6376 E10 1 0
987 0980 E18 0 0

Thanks in advance,

PP

答案1

得分: 1

以下是代码部分的翻译:

	do until (last.id);
		set have;
		by id;
		if value = 'E10' then E10 = 1;
		if value = 'E11' then E11 = 1;
	end;

	do until (last.id);
		set have;
		by id;
		if E10 = 1 and E11 = 1 then combination = 1;
		else combination = 0;
		output;
	end;

	drop E:;
run;

如果你需要进一步的翻译或解释,请告诉我。

英文:

Assumption is that the data is already sorted by id.

data want;
	do until (last.id);
		set have;
		by id;
		if value = 'E10' then E10 = 1;
		if value = 'E11' then E11 = 1;
	end;

	do until (last.id);
		set have;
		by id;
		if E10 = 1 and E11 = 1 then combination = 1;
		else combination = 0;
		output;
	end;

	drop E:;
run;
 id   case  value  dummy  combination
123   4736   E10     1        1
123   1254   N65     0        1
123   997    E11     1        1
123   7655    x      0        1
987   1234    x      0        0
987   6376   E10     1        0
987   980    E18     0        0

huangapple
  • 本文由 发表于 2023年3月7日 21:00:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662307.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定