Date: Tue, 7 Feb 2012 17:33:06 -0500
Reply-To: Jim Groeneveld <jim.1stat@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim.1stat@YAHOO.COM>
Subject: Re: Q: Define format for array elements
Hi friends,
Well, I came up with the following solution for assigning a specific format
for array elements, which are variables with unknown names to the program.
I wouldn't know of a simpler solution. If anyone of you knows of an easier
solution then please tell me. I would SAS offered an easy solution itself.
%MACRO FmtArray (Dataset=, Array=, Format=);
CALL EXECUTE ("DATA &Dataset; SET &Dataset; FORMAT ");
DO __I = 1 TO DIM(&Array);
CALL EXECUTE (VNAME(&Array[__I]) || ' ');
END;
CALL EXECUTE ("&Format ; RUN;");
DROP __I;
%MEND FmtArray;
DATA Example;
A='a'; B='b'; C='c';
X=1; Y=2; Z=3;
ARRAY ABC A B C;
ARRAY XYZ X Y Z;
%FmtArray (Dataset=Example, Array=ABC, Format=$CHAR3.);
%FmtArray (Dataset=Example, Array=XYZ, Format=5.1);
RUN;
PROC CONTENTS DATA=Example OUT=Contents NOPRINT; RUN;
PROC PRINT DATA=Contents (KEEP=Name Format FormatL FormatD); RUN;
Thank you all for your thoughts and ideas.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician/SAS consultant
http://jim.groeneveld.eu.tf