我创建了一个宏变量&dirLSB, 然后使用以下代码设置其路径:
%let dirLSB = "/folders/myfolders/LSB/";
libname FLOWER &dirLSB; *Worked!;
data FLOWER.magnolia;
infile "&dirLSB.Mag.dat";
input ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight AgeBloom
Type $ Color $; run;
proc print data=FLOWER.magnolia; title "Magnolias"; run;
看起来很简单-在数据集中, 但是,我遇到了如下错误:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data FLOWER.magnolia;
74 infile "&dirLSB.Mag.dat";
NOTE: Line generated by the macro variable "DIRLSB".
74 ""/folders/myfolders/LSB/"Mag.dat
_
23
ERROR 23-2: Invalid option name /.
74 ! ""/folders/myfolders/LSB/"Mag.dat
_______
23
ERROR 23-2: Invalid option name FOLDERS.
74 ! ""/folders/myfolders/LSB/"Mag.dat
_________
23
ERROR 23-2: Invalid option name MYFOLDERS.
74 ! ""/folders/myfolders/LSB/"Mag.dat
___
23
ERROR 23-2: Invalid option name LSB.
75 input ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight
76 AgeBloom Type $ Color $;
77 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set FLOWER.MAGNOLIA may be incomplete. When this step was stopped there were 0 observations and 6 variables.
WARNING: Data set FLOWER.MAGNOLIA was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.02 seconds
78
79 proc print data=FLOWER.magnolia;
80 title "Magnolias";
81 run;
NOTE: No observations in data set FLOWER.MAGNOLIA.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
82
83 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
96
我首先在“文件夹快捷方式”中设置“ LSB”, 然后我检查了它的属性并意识到了它的路径 作为“ / folders / myfolders / LSB /”,然后我更改了代码。 我成功创建了一个名为“ FLOWER”的库, 因此,我无法理解自己出了什么问题。
非常感谢!!
答案 0 :(得分:2)
修复
将宏变量分配更改为不带双引号。
%let dirLSB = /folders/myfolders/LSB/;
因此,最终的infile
语句将正确无误,并且只要您进行了编码
infile "/folders/myfolders/LSB/.Mag.dat";
说明
宏变量(也称为宏符号)具有一个值,当使用前&(“&”号)字符请求符号解析并在其后跟可选字符时,该值将置于处理流中。 (句点)字符(定点)。 SAS确定要解析的&符号名称时,任何非名称字符也将充当哨兵。
宏变量始终是“字符串”,但从DATA步骤的编程意义上来说不是。因此,赋值语句
%let dirLSB = "/folders/myfolders/LSB/";
正在设置一个宏变量,该变量的字面值实际上是以下字符序列:
解析宏变量时,双引号进入处理流,因此语句
infile "&dirLSB.Mag.dat";
将按照您进行编码的方式处理
infile ""/folders/myfolders/LSB/"Mag.dat";
您应将其识别为“陷入困境”的声明。