楼主: 燕婉
3281 7

[原创博文] 数据集记录数不足 补充空行 [推广有奖]

  • 0关注
  • 0粉丝

学前班

90%

还不是VIP/贵宾

-

威望
0
论坛币
9 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
33 点
帖子
3
精华
0
在线时间
0 小时
注册时间
2012-6-24
最后登录
2012-6-25

楼主
燕婉 发表于 2012-6-24 22:16:13 |AI写论文
1论坛币
如果限制某数据集的行数,如果记录数不足n(如6)条时,补充空行,该如何编写程序,如:
data a;
set a;
if.... then ...
run;

关键词:数据集 Data Then 编写程序 Set 编写程序 如何

沙发
webgu 发表于 2012-6-24 23:06:49
example:
data a;
x=1;output;
x=2;output;
x=3;output;
x=4;output;
run;

data b (drop=i j);
do i=1 to  nobs;
  set a end=last nobs=nobs;
  output;
end;
  if last and (i-1)<6 then do;
    do j=1 to (6-i+1);
     x=. ;output;
        end;
        end;
run;
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

藤椅
燕婉 发表于 2012-6-24 23:22:39
webgu 发表于 2012-6-24 23:06
example:
data a;
x=1;output;
如果变量不止一个呢?

板凳
tj0412ymy 发表于 2012-6-24 23:48:42
燕婉 发表于 2012-6-24 23:22
如果变量不止一个呢?
  1. data test(drop=i);
  2. set sashelp.class end=eof nobs=obs;
  3. output;
  4. call missing(of _all_);
  5. if eof then do i=1 to 25-obs;
  6. output;
  7. end;
  8. run;
  9. proc print noobs;run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
webgu + 1 + 1 + 1 不错。

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

对SAS和统计方面感兴趣的朋友,请加SAS学习和认证讨论群:169157207。欢迎在群上讨论!

报纸
bobguy 发表于 2012-6-26 07:38:26
tj0412ymy 发表于 2012-6-24 23:48
Moving the  call missing(of _all_) into the loop makes it logically better and save (19) times unwanted execution of  "call missing(of _all_)".

data test(drop=i);
    set sashelp.class end=eof ;
    output;
   
    if eof then do;
      do i=1 to 6;
          call missing(of _all_);
      output;
    end;
    run;

    proc print noobs;run;

地板
tj0412ymy 发表于 2012-6-26 09:40:08
bobguy 发表于 2012-6-26 07:38
Moving the  call missing(of _all_) into the loop makes it logically better and save (19) times unw ...
Everyone knows this logic. Did you test your code? Did it really works except missing an end? hehe~
对SAS和统计方面感兴趣的朋友,请加SAS学习和认证讨论群:169157207。欢迎在群上讨论!

7
bobguy 发表于 2012-6-27 08:06:14
tj0412ymy 发表于 2012-6-26 09:40
Everyone knows this logic. Did you test your code? Did it really works except missing an end? he ...
This one even better. It saves additional 5 times of call missing(of _all_).

data test(drop=i);
    set sashelp.class end=eof ;
    output;
   
    if eof then do;
      call missing(of _all_);
      do i=1 to 6;
      output;
    end;
   end;
    run;

    proc print noobs;run;

8
jjtww 发表于 2012-7-10 17:47:09
call missing 得到的全是数值型的,可遇到字符型怎么办?得分组考虑才行。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 11:57