所以我需要在SAS上输入一个表格,但我无法弄清楚如何制作字符

时间:2015-10-12 21:23:27

标签: sas

所以数据应该主要是字符

 data pounds;
 input name $1-14 from 16-30 to 32-41 pounds_million $ 44-47
 datalines;
 Angel Di Maria Real Madrid     Man United  59.7
 Diego Costa    Atletico Madrid Chelsea     32
 Cesc Fabregas  Barcelona       Chelsea     27
 Romelu Lukaku  Chelsea         Everton     28
 ;

  run;
  proc print = pounds;
  var name from to pounds_million;
  run;

我意识到这可能非常微不足道,但这是我第一次使用SAS

2 个答案:

答案 0 :(得分:0)

您可以使用@(指针)和$x.(字符变量x的长度)和:修饰符来强制它读取空格作为变量例如

data pounds ;
  input @1  name : $14.
        @16 from : $15.
        @32 to   : $10.
        @44 pounds_million 
        ;
/*
RULER
         1         2         3         4         5
12345678901234567890123456789012345678901234567890
*/
datalines ;
Angel Di Maria Real Madrid     Man United  59.7
Diego Costa    Atletico Madrid Chelsea     32
Cesc Fabregas  Barcelona       Chelsea     27
Romelu Lukaku  Chelsea         Everton     28
;
run ;

SAS infile声明文档> https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm

SAS输入声明文档> https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146292.htm

答案 1 :(得分:0)

你快到了。 $表示变量是字符;你在第一个变量上正确使用它,但在第四个变量上没有正确,在第二个和第三个变量上错误地不是。你的职位也是一个人。

 data pounds;
 input name $1-15 from $ 17-31 to $ 33-43 pounds_million 44-47;
 datalines;
 Angel Di Maria Real Madrid     Man United  59.7
 Diego Costa    Atletico Madrid Chelsea     32
 Cesc Fabregas  Barcelona       Chelsea     27
 Romelu Lukaku  Chelsea         Everton     28
 ;

  run;
  proc print data = pounds;
  var name from to pounds_million;
  run;