楼主: dxystata
2136 8

如何根据数据集得到变量的format [推广有奖]

版主

大师

34%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
182307 个
通用积分
15205.0502
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
290922 点
帖子
5369
精华
1
在线时间
13474 小时
注册时间
2006-6-21
最后登录
2024-4-23

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

100论坛币
  1. data aaa;
  2. input name$ format$50.;
  3. cards;
  4. sex  1=男|2=女
  5. hy   1=已婚|2=未婚
  6. mz   1=汉|2=少数民族
  7. xy1  0=不吸烟|1=偶尔吸烟|2=经常吸烟
  8. ;
  9. run;
复制代码
如何根据数据集aaa得到sexfmt. hyfmt. mzfmt. xy1fmt.,谢谢!

关键词:format FORMA form RMA Mat 少数民族 如何

本帖被以下文库推荐

沙发
farmman60 发表于 2014-11-23 23:31:53 |只看作者 |坛友微信交流群
dxystata 发表于 2014-11-24 11:10
proc format;
        value  groupfmt 1="1+2" 2="3";
run;
  1. data aaa;
  2. input;
  3. name=scan(_infile_,1,' ');
  4. format=scan(_infile_,-1,' ');
  5. cards;
  6. sex  1=male|2=female
  7. hy   1=married|2=unmarried
  8. mz   1=han|2=minority
  9. xy1  0=no|1=occasional|2=often
  10. group 1=1+2|2=3
  11. ;
  12. run;

  13. data _null_;
  14.   set aaa end=last;
  15.   if _n_=1 then call execute(
  16.        'proc format;');
  17.   call execute('value ' ||strip(name)||"fmt");
  18.   do i=1 to count(format,'|')+1;
  19.     string=scan(format,i,'|');
  20.         _string=prxchange('s/(\.*\=)(.*)/$1"$2"/i',-1,string);
  21.            call execute(_string);
  22.   end;
  23.     call execute(';');
  24. if last then call execute('; run;');
  25. run;
复制代码

使用道具

藤椅
teqel 发表于 2014-11-24 00:41:49 |只看作者 |坛友微信交流群
sashelp.vcolumn: format

使用道具

板凳
farmman60 发表于 2014-11-24 02:50:04 |只看作者 |坛友微信交流群
  1. data aaa;
  2. input;
  3. name=scan(_infile_,1,' ');
  4. format=scan(_infile_,-1,' ');
  5. cards;
  6. sex  1=male|2=femal
  7. hy   1=married|2=unmarried
  8. mz   1=han|2=minority
  9. xy1  0=no|1=occasional|2=often
  10. ;
  11. run;

  12. data _null_;
  13.   set aaa;
  14.   if _n_=1 then call execute(
  15.        'proc format;');
  16.   call execute('value ' ||strip(name)||"fmt");
  17.   do i=1 to count(format,'|')+1;
  18.     string=scan(format,i,'|');
  19.            call execute(string);
  20.   end;
  21.     call execute(';');
  22. if last then call execute('; run;');
  23. run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
teqel + 1 + 1 + 1 观点有启发

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

使用道具

报纸
dxystata 发表于 2014-11-24 08:06:25 |只看作者 |坛友微信交流群
farmman60 发表于 2014-11-24 02:50
变量 last 未初始化。

name=scan(_infile_,1,' ');
format=scan(_infile_,-1,' ');
这两句作用是?谢谢!

使用道具

地板
dxystata 发表于 2014-11-24 11:07:57 |只看作者 |坛友微信交流群
  1. data aaa;
  2. input;
  3. name=scan(_infile_,1,' ');
  4. format=scan(_infile_,-1,' ');
  5. cards;
  6. sex  1=male|2=femal
  7. hy   1=married|2=unmarried
  8. mz   1=han|2=minority
  9. xy1  0=no|1=occasional|2=often
  10. xx   1=left|2=right|3=1+2
  11. ;
  12. run;

  13. data _null_;
  14.   set aaa end=last;
  15.   if _n_=1 then call execute(
  16.        'proc format;');
  17.   call execute('value ' ||strip(name)||"fmt");
  18.   do i=1 to count(format,'|')+1;
  19.     string=scan(format,i,'|');
  20.            call execute(string);
  21.   end;
  22.     call execute(';');
  23. if last then call execute('; run;');
  24. run;
复制代码


运行出错!

使用道具

7
dxystata 发表于 2014-11-24 11:10:46 |只看作者 |坛友微信交流群
farmman60 发表于 2014-11-24 02:50
proc format;
        value  groupfmt 1="1+2" 2="3";
run;

程序中能否加引号呢?

使用道具

8
dxystata 发表于 2014-11-24 23:31:05 |只看作者 |坛友微信交流群
farmman60 发表于 2014-11-23 23:31
运行后出错!

使用道具

9
farmman60 发表于 2014-11-24 23:42:37 |只看作者 |坛友微信交流群
dxystata 发表于 2014-11-24 23:31
运行后出错!
it seems that there is problem for this web editor.

string=prxchange('s/(\.*\=)(.*)/$1"$2"/i',-1,string);
need dollar symbole before 1 and 2.


data aaa;
input;
name=scan(_infile_,1,' ');
format=scan(_infile_,-1,' ');
cards;
sex  1=male|2=female
hy   1=married|2=unmarried
mz   1=han|2=minority
xy1  0=no|1=occasional|2=often
group 1=1+2|2=3
;
run;

data _null_;
  set aaa end=last;
  if _n_=1 then call execute(
       'proc format;');
  call execute('value ' ||strip(name)||"fmt");
  do i=1 to count(format,'|')+1;
    string=scan(format,i,'|');
        _string=prxchange('s/(\.*\=)(.*)/$1"$2"/i',-1,string);
           call execute(_string);
  end;
    call execute(';');
if last then call execute('; run;');
run;

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-23 17:25