Arrays 宏中的let函数和数组语句

Arrays 宏中的let函数和数组语句,arrays,macros,sas,Arrays,Macros,Sas,我不熟悉SAS和宏。我希望获得一些帮助,以了解以下代码行的作用: %let numbercccats=201; DATA &OUTDSN(KEEP=HICno CASE &prefix.CC1-&prefix.CC&numbercccats. ID) ERR; SET TEMP1; by ID; length cc $4.; cc=left(addxg); RETAIN &prefix.CC1-&prefix.CC&numberccc

我不熟悉SAS和宏。我希望获得一些帮助,以了解以下代码行的作用:

%let numbercccats=201;

DATA &OUTDSN(KEEP=HICno CASE &prefix.CC1-&prefix.CC&numbercccats. ID) ERR;
SET TEMP1;
by ID;
length cc $4.;

cc=left(addxg);

RETAIN &prefix.CC1-&prefix.CC&numbercccats. 0 ; 
ARRAY C(&numbercccats.)  &prefix.CC1-&prefix.CC&numbercccats.;

谢谢。

我已经添加了我对SAS代码的每一行的解释,并与下面的代码相关联:

%let numbercccats=201;
/*Creates macro variable numbercccats with value 201*/

DATA &OUTDSN
/*Creates a SAS table; the table name will be te value in the macro variable OUTDSN*/

(KEEP=HICno CASE &prefix.CC1-&prefix.CC&numbercccats. ID) ERR;
/*Keep statement only keeps the column specified above*/
/*&prefix.CC1-&prefix.CC&numbercccats. is resolved to the value of the macro prefix concatinated with CC1-CC201*/
/*in other words you bring/keep 200 columns CC1,CC2,...CC201*/

SET TEMP1;
/*The input/source table is TEMP1 */

by ID;
/*Group by ID*/

length cc $4.;
/*Creates a new column named CC of length 4*/

cc=left(addxg);
/*Assigns the value of addxg to the new column cc, and removes leading spaces */

RETAIN &prefix.CC1-&prefix.CC&numbercccats. 0 ; 
/*for all the records with the same ID SAS won't change the value of the 200 columns CC1 to CC201*/

ARRAY C(&numbercccats.)  &prefix.CC1-&prefix.CC&numbercccats.;
/*An array called C of length 201 is created pointing to the 201 columns: CC1-CC201 */

也许你可以添加关于你使用的语言的标签?设置TEMP1/*创建的新表名为TEMP1*/???????使用“set”,表格将被读取而不是创建。谢谢@momo1644。为了澄清这条语句-数组C(&numberccats.)和prefix.CC1-&prefix.CC&numberccats。;哪一个是指针数组?是C(&numberccats.)吗?我不确定这是声明2个数组的语句还是其他语句。你说它只是一个指针数组声明?如果我在理解这行代码时出错,请纠正我。数组名是C,delcaration行转换为C(201)CC1-CC201。因此,如果您在201个数组对象上循环,您将查看201列值。这个简短的SAS数组教程将让您很好地理解它的工作原理:感谢您的确认。我不知道为什么会这样做,因为我认为CC(20)会把你带到第20个索引。然而,您提到的“column”基本上应该是CC(1,20)。我将继续学习本教程,因为我正试图更多地理解数组。谢谢。