LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 21 Sep 2006 20:22:17 -0400
Reply-To:     "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Subject:      Re: Is it possible to load a dataset column into a macro array?
Comments: To: sas-l@uga.edu

Peter Constantinidis wrote: ... alot of stuff ...

Re: Is it possible to load a dataset column into a macro array?

Yes, use Proc SQL. But try to see if you don't need macro at all first.

proc sql noprint; select distinct age into :age1-:age99999 from sashelp.class; %let age_count = &SQLOBS; quit;

data _null_; do i = 1 to &age_count; age = symget(cats('age',i)); put i= age=; end; run;

With macro arrays, used in macro programs (not shown), you run into needing a nested token that looks like &&arrayname&index.

A null data step and call execute statements can be used to avoid macro all together. This is a ridiculously contrived mickey mouse example, and should never ever be used in a real world situation (use by statement instead)

proc sql; create view ages as select distinct age from sashelp.class; quit;

data _null_; set ages; call execute (cats('proc print data=sashelp.class; where age=',age,';run;')); run;

--or-- even more mickey mouse, invoking a macro multiple times, where each argument is based on a value in a table

proc sql; create view ages as select distinct age from sashelp.class; quit;

%macro mystupidprint(data=, where=); proc print data=&data; where &where; run; %mend;

data _null_; set ages; call execute ( cats('%mystupidprint' , '(' , ' data=sashelp.class' , ', where=age=',age , ')' ) ); run;

-- Richard A. DeVenezia http://www.devenezia.com/


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