Date: Tue, 16 Sep 2008 23:15:41 +1000
Reply-To: Scott Bass <sas_l_739.at.yahoo.dot.com.dot.au@PESTO.CC.UGA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott Bass <sas_l_739.at.yahoo.dot.com.dot.au@PESTO.CC.UGA.EDU>
Subject: Re: Joining data sets that are created with macro do loops
Great replies so far...
Two more approaches:
1. However your macro is creating your datasets (and you haven't shown us
that), why bother mucking with your macro array? Just code something like:
%global datasets; /* at the top of the macro, outside any macro loops.
doesn't need to be global if your macro itself is doing the dataset
concatenation. */
data set creation code goes here;
run;
%let datasets = &datasets &syslast; /* right after your dataset creation
code */
%mend;
data all;
set &datasets;
run;
2. You could do something with the dictionary tables (depends if your work
library is clean). Something like:
proc datasets lib=work kill nowarn nolist;
quit;
%your macro goes here;
proc sql noprint;
select catx(".",libname,memname) into :datasets separated by " "
from dictionary.tables
where libname = "WORK" /* or whatever your libname is */
;
quit;
data all;
set &datasets;
run;
If you use a naming convention for your datasets (as opposed to abc cde
fgh), you don't need to clean out work first:
proc sql noprint;
select catx(".",libname,memname) into :datasets separated by " "
from dictionary.tables
where libname = "WORK" and memname like "PREFIX^_%" escape "^" /* read
the SQL doc on special character underscore and escape clause */
;
quit;
HTH,
Scott
"Suren gc" <gc_suren@YAHOO.COM> wrote in message
news:200809151953.m8FJ71Om006062@malibu.cc.uga.edu...
>I was trying to find a way where I could concatenate data sets that are
> created on the fly using macro do loops by referencing them to the macro
> variable rather than using the macro variable value.
>
> Rather that using "set datanames" to concatenate datasets, I was trying
> to
> find a way where the macro variable could be used and could be
> automatically adjusted to fit the number of data sets.
>
> %macro join;
> %do i = 1 to 3;
> %if &i=1 %then %let data=abc;
> %if &i=2 %then %let data=cde;
> %if &i=3 %then %let data=fgh;
>
> data All;
> set abc cde fgh;/* I would like to have a code such that the data sets
> here
> are automatically set based on the data sets created during the macro
> loop.*/
>
> %end;
> %mend join;
>
> Thanks,
> Suren