导入包含引号的sas文件

时间:2015-11-25 07:26:55

标签: sas

我想知道如何导入包含引号的SAS数据文件("")。

例如,该文件包含两个变量:

 "gray or green", "blond"
 "ble", "red"
 "brown", "rou"
 "gray or green", "blond"
 "blue", "brown"
 "brown", "black"
 "gray or green", "black"

我尝试了以下代码:

data color ; 
  infile 'file path' DLM = " , " ; 
  input v1 $ v2 $ ; 
  v1 label = "eyes colour" v2 = "hair colour"; 
run; 

proc print data = color; 
run;

1 个答案:

答案 0 :(得分:1)

格式为CSV,您可以使用DSD选项读取文件。

  

DSD指定当数据值用引号括起来时,值中的分隔符将被视为字符数据。 DSD选项更改SAS在使用LIST输入时如何处理分隔符,并将默认分隔符设置为逗号。指定DSD时,SAS会将​​两个连续的分隔符视为缺失值,并从字符值中删除引号。

https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm

data want;
infile cards DSD;
informat var1 var2 $20.;
input var1 $ var2 $;
cards;
"gray or green", "blond"
 "ble", "red"
 "brown", "rou"
 "gray or green", "blond"
 "blue", "brown"
 "brown", "black"
 "gray or green", "black"
 ;
 run;