全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
9156 6
2014-01-10
悬赏 50 个论坛币 已解决
想请问大家一个问题:

我想利用如下代码完成某种宏,
复制代码

出来的数据集应该是这样的:
abChardef
STUDYID

Study Identifier

Char

15



EG.STUDYID
BRTHDTC

Date/Time  of Birth

Char

19



ADSL.BRTHDTC
AGEGR1

Age  Group

Char

15

<40,
    >=40 and < 60,
    >= 60

ADSL.AGEGR1

AGEGR1N

Age  Group (N)

Num

8



ADSL.AGEGR1N
注:<40,后面是个换行符。
注:datalines中的(\t)代表从excel直接复制过来的转义符。

中间的datalines为每次手动黏贴进去的东西。
现在我想把这些数据读入,其中用来分隔的是excel的分隔符:\t,就是按照\t的转义符一口气读下去。

为什么不直接用import,我有如下苦衷:

因为公司用的是unix sas,故中间有些难弄得东西
1. 据悉proc import不能读入xlsx,这是死穴。
2. 就算能读xlsx,还有一大问题:文件名中可能存在空格,例如:‘/user1/abc/a b  c.xlsx’

所以只好出此下策,加入一个手动环节,然后想用中间的过程步来自动识别读入的数据。

还望给与回复,非常感谢。
祝阅者新年快乐,马上有房有车有房车,还没毕业的就马上有SCI~~

更新:
感觉貌似不行,。。。因为datalines会把制表符直接转换成空格,例如:
input a $1. @@;

  if a = '09'x then input '|' @@;
  else  input a $1. @@;
这样都是没效果的。。

那么,能否通过import的 ‘/user1/abc/a b  c.xlsx’ 解决呢。。。

最佳答案

邓贵大 查看完整内容

(1) you cannot import XLSX files directly because MS XLSX files are XML based. XML is a nested/hierarchical structure that is very hard for importing (which is designed for tabular structures). (2) if you save one XLSX into a tab-delimited flat text file, then you have to save it either in a shared location or move it into UNIX in binary mode (the tabs will become blanks in ASCII mode, thus mess ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-1-10 15:42:48
(1) you cannot import XLSX files directly because MS XLSX files are XML based. XML is a nested/hierarchical structure that is very hard for importing (which is designed for tabular structures).
(2) if you save one XLSX into a tab-delimited flat text file, then you have to save it either in a shared location or move it into UNIX in binary mode (the tabs will become blanks in ASCII mode, thus mess up your formatting). An INFILE statement with DLM='09'x and TERMSTR=CRLF should work.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-1-10 15:55:52
回去试试。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-1-10 16:20:20
个人感觉有点像这个意思:

infile datalines dlm='prxparse(/\t/)';

如果能有办法把datalines里的内容直接用正则替换也是个办法,但是对于datalines。。。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-1-13 01:38:48
This code did not completely reach your request. newline should be deleted first.

data a;
infile datalines dlm=','  truncover dsd ;
input @;
_infile_=tranwrd(_infile_,'(\t)',',');
input a $ b :$18. c $ d $ e: $24. f $15.;
datalines;
STUDYID(\t)Study Identifier(\t)Char(\t)15(\t) (\t)EG.STUDYID
BRTHDTC(\t)Date/Time of Birth(\t)Char(\t)19(\t)data9.(\t)ADSL.BRTHDTC
AGEGR1(\t)Age Group(\t)Char(\t)15(\t)"<40,>=40 and < 60,>= 60"(\t)(\t)ADSL.AGEGR1
AGEGR1N(\t)Age Group (N)(\t)Num(\t)8(\t)(\t)ADSL.AGEGR1N
;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-1-13 09:54:32
farmman60 发表于 2014-1-13 01:38
This code did not completely reach your request. newline should be deleted first.

data a;
Hi farmman,

Thank you to given me powerful support first.
But you just misunderstood my mind.
'(\t)' is not a delimiter which contain '\t' with a pair of brackets.
It's means an invisible mark between two cell, for example, from EXCEL.
When you copy two cells form EXCEL to notepad, it contain a '\t' between two cells.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群