楼主: dxystata
1662 9

[问答] 如何生成两列新变量 [推广有奖]

版主

已卖:302份资源

大师

37%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
183395 个
通用积分
15333.1475
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
298627 点
帖子
5586
精华
1
在线时间
13632 小时
注册时间
2006-6-21
最后登录
2025-12-22

初级学术勋章 初级热心勋章 中级热心勋章 初级信用勋章

楼主
dxystata 发表于 2021-4-25 00:53:43 |AI写论文
15论坛币
微信截图_20210425004140.png
如何基于附件中的estimate数据集生成两列新变量class1和class0,如下:
class1        class0
adeno 1     squamous
large 1       squamous
small 1       squamous


谢谢!

estimate.rar (1.06 KB) 本附件包括:
  • estimate.sas7bdat

关键词:新变量 estimate Small Large Tima

沙发
乐天天12300 发表于 2021-4-25 21:23:23
  1. libname mylib "desktop";

  2. data mydata;
  3.     length class0 class1  $20;
  4.     do i=last to 1 by -1;
  5.             set mylib.estimate nobs=last point=i;
  6.                 retain class0 "";
  7.                 pos=prxmatch("/ /",left(Parameter));
  8.                 if i=last then class0=substr(Parameter, pos);
  9.                 else class1=substr(parameter,pos);
  10.                 if i^=last then output;
  11.         end;
  12.         stop;
  13.         drop pos;
  14. run;
复制代码
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 观点有启发

总评分: 经验 + 100  热心指数 + 1   查看全部评分

藤椅
dxystata 发表于 2021-4-26 06:28:43
乐天天12300 发表于 2021-4-25 21:23
stop语句的作用?
输出的class1 class0两边好像有空格。
谢谢!

板凳
乐天天12300 发表于 2021-4-26 09:09:35 来自手机
用compress去掉所有空格

报纸
whymath 发表于 2021-4-28 22:13:38
乐天天12300 发表于 2021-4-25 21:23
你这样是否将整个数据集变成倒序了
已有 1 人评分经验 收起 理由
dxystata + 100 热心帮助其他会员

总评分: 经验 + 100   查看全部评分

地板
nbn523005 发表于 2021-5-10 13:33:31
三种方法,1.
1.SQL过程,你去看一下SQL添加列操作;
2.生成两列组成的新数据集,然后合并。
3.直接原数据集,加两列,set语句添加变量值;


已有 1 人评分经验 收起 理由
dxystata + 100 热心帮助其他会员

总评分: 经验 + 100   查看全部评分

7
dxystata 发表于 2022-11-4 09:16:31
whymath 发表于 2021-4-28 22:13
你这样是否将整个数据集变成倒序了
倒序如何解决?谢谢!

8
learsaas 发表于 2022-11-4 13:58:11
  1. data result;
  2.         set mylib.estimate nobs=ncount;
  3.         length class1 class0 $20;
  4.         if _n_=1 then set mylib.estimate(keep=Parameter rename=(Parameter=Parameter0)) point=ncount;
  5.         class1=left(substr(left(Parameter),index(left(Parameter),' ')));
  6.         class0=left(substr(left(Parameter0),index(left(Parameter0),' ')));
  7.         if _n_ ne ncount;
  8.         drop Parameter0;
  9. run;
复制代码
已有 1 人评分经验 学术水平 热心指数 收起 理由
dxystata + 100 + 2 + 2 热心帮助其他会员

总评分: 经验 + 100  学术水平 + 2  热心指数 + 2   查看全部评分

9
whymath 发表于 2023-9-27 16:04:31
这里的逻辑是什么?

10
AngleeZZ 发表于 2023-9-27 16:21:37
  1. data result1;  set test;  where parameter in ("adeno 1", "large 1","smarll 1");  id = whichc(parameter, "adeno 1", "large 1","smarll 1");  class1 = estimate;run;
  2. data result2;  set test;  where parameter in ("sguamous");  id = 1;  class0 = estimate;run;
  3. data result;  merge result1 result2;  by id;run;
复制代码
xxx_1.png



红色部分作新变量class1
蓝色部分作新变量class0??



已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 热心帮助其他会员

总评分: 经验 + 100  热心指数 + 1   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-7 06:22