以不同格式挑战的数据驱动

sta*_*tat 0 format sas datastep

我想带着这些日子面临的挑战来到这里.

基本上对于每个记录,应该在put语句中使用不同的格式,并且它在自己的数据中定义.

挑战不是分割datasteps并在datastep中获得想要的结果,所以避免明显的%do循环和类似:)

proc format;
    value $a 'FRS'='FIRST';
    value $b 'SCN'='SECOND';
run;
data a;
    length var $3 res $10 fmt $5;
    var='FRS'; fmt='$a.'; res=''; output;
    var='SCN'; fmt='$b.'; res=''; output;
run;
data b;
    set a;

    *your code goes here, the result should go into res variable;
    *and should be the "putted" value of var using fmt as format.;
    *an obviously non working version can be found here below;

    res=put(var,fmt);
run;
Run Code Online (Sandbox Code Playgroud)

下面是它的样子,res是预期的结果:

VAR  FMT  RES
---------------
"FRS" $a. =put("FRS",$a.)="FIRST"
"SCN" $b. =put("SCN",$b.)="SECOND"
Run Code Online (Sandbox Code Playgroud)

Tom*_*Tom 6

我不确定我理解这个问题,但看起来你只想使用这个PUTC()功能.如果您的变量是数字,则可以使用该PUTN()函数.

res=putc(var,fmt);
Run Code Online (Sandbox Code Playgroud)

  • @stat你绝对可以使用一个变量来包含带有'PUTC`和`PUTN`函数的格式规范.这是它们与`PUT`功能之间的主要区别之一. (5认同)