LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2012, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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


Back to: Top of message | Previous page | Main SAS-L page