我在SAS中编程,想使用LUA编写一个创建xml文件
因此,首先,我启动proc LUA
并传递文件名
;
%let file = \\ergo\applications\CRS\BSUG\new.xml;
proc lua restart;
submit;
local file_name = sas.symget("file")
print (file_name)
-接下来,我打开文件进行写入,编写并关闭文件
file = io.open (file_name, "w")
file:write ("<test>", "\n")
file:write ("write to file", "\n")
file:write ("</test>", "\n")
file:close()
-当然也要停止LUA
endsubmit;
run;
/ *这有效:文件是使用此内容创建的
<test>
write to file
</test>
但是它会在日志中显示以下消息
NOTE: Lua initialized.
\\ergo\applications\CRS\BSUG\new.xml
ERROR: An exception has been encountered.
Please contact technical support and provide them with the following traceback information:
The SAS task name is [LUA (2)]
ERROR: Read Access Violation LUA (2)
Exception occurred at (89400CB7)
Task Traceback
Address Frame (DBGHELP API Version 4.0 rev 5)
00007FFD89400CB7 000000000802F1F0 ntdll:RtlAllocateHeap+0x27
0000000007ED2ACD 000000000802F1F8 sasplua:tkvercn1+0x81A8D
0000000007ED0E7F 000000000802F250 sasplua:tkvercn1+0x7FE3F
0000000007ED0D17 000000000802F280 sasplua:tkvercn1+0x7FCD7
0000000007ECF711 000000000802F2B0 sasplua:tkvercn1+0x7E6D1
0000000007E62609 000000000802F300 sasplua:tkvercn1+0x115C9
0000000007E74A7D 000000000802F410 sasplua:tkvercn1+0x23A3D
0000000007E85C7E 000000000802F530 sasplua:tkvercn1+0x34C3E
0000000007E74349 000000000802F570 sasplua:tkvercn1+0x23309
0000000007E788A4 000000000802F8D0 sasplua:tkvercn1+0x27864
0000000007E78A9D 000000000802F940 sasplua:tkvercn1+0x27A5D
0000000007E69746 000000000802F9A0 sasplua:tkvercn1+0x18706
0000000007E523A2 000000000802F9F0 sasplua:tkvercn1+0x1362
0000000007E5224E 000000000802FB10 sasplua:tkvercn1+0x120E
0000000007E529F4 000000000802FBF0 sasplua:tkvercn1+0x19B4
0000000001A289DB 000000000802FBF8 sashost:Main+0x10EBB
0000000001A2E61D 000000000802FF50 sashost:Main+0x16AFD
00007FFD875613F2 000000000802FF58 KERNEL32:BaseThreadInitThunk+0x22
00007FFD893E54F4 000000000802FFD0 ntdll:RtlUserThreadStart+0x34
NOTE: The SAS System stopped processing this step because of errors.
我不知道这是纯粹的LUA问题,还是与SAS中的proc LUA
相关的问题。
注意:当我注释掉io.write
语句时,我仍然遇到问题。
答案 0 :(得分:1)
您的代码对我来说很好(在SYSVLONG=9.04.01M3P062415
,SYSSCP=LIN X64
上)。
也许尝试以下略有不同的方法?
%let file = %sysfunc(pathname(work))/new.xml;
proc lua restart;
submit;
local file_name = sas.symget("file")
print (file_name)
file = io.open (file_name, "w")
io.output(file) -- sets default output
io.write ("<test>", "\n")
io.write ("write to file", "\n")
io.write ("</test>", "\n")
io.close(file)
endsubmit;
run;