让宏中的函数和数组语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了让宏中的函数和数组语句相关的知识,希望对你有一定的参考价值。
我是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.;
谢谢。
答案
我已经添加了我对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 */
以上是关于让宏中的函数和数组语句的主要内容,如果未能解决你的问题,请参考以下文章