让宏中的函数和数组语句

问题描述 投票:2回答:1

我是SAS和Macros的新手。我想帮助理解以下代码行正在做什么:

%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.;

谢谢。

arrays macros sas
1个回答
0
投票

我已经添加了我对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 */
© www.soinside.com 2019 - 2024. All rights reserved.