| Date: | Thu, 30 Apr 2009 11:07:20 -0400 |
| Reply-To: | oloolo <dynamicpanel@YAHOO.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | oloolo <dynamicpanel@YAHOO.COM> |
| Subject: | Re: How to create a dataset by appending a single (i.e same)
dataset multiple times.?? |
| Content-Type: | text/plain; charset=ISO-8859-1 |
Great! Learnt.
On Thu, 30 Apr 2009 03:06:15 -0400, S=?ISO-8859-1?Q?=C3=B8ren?= Lassen
<s.lassen@POST.TELE.DK> wrote:
>Brilliant idea!
>This is a good method if the whole source table can be held in memory.
>To make it really fast, though, you should use PEEKC() and POKE()
>to move things in and out of the arrays. I have written this
>macro, which does that:
>
>%macro repeatds(data=,out=,n=);
> %local memname libname nobs charlen firstchar numlen firstnum;
> %if %length(&data)=0 %then
> %let data=&syslast;
> %let data=%upcase(&data);
> %if %length(%scan(&data,2,.))=0 %then %do;
> %let memname=&data;
> %let libname=%scan(%upcase(%sysfunc(getoption(user))) WORK,1);
> %end;
> %else %do;
> %let libname=%scan(&data,1,.);
> %let menname=%scan(&data,2,.);
> %end;
>
>proc sql noprint;
> select sum(length) into :charlen from dictionary.columns
> where libname="&libname" and memname="&memname" and type='char';
> select name into :firstchar from dictionary.columns
> where libname="&libname" and memname="&memname" and type='char'
> having varnum=min(varnum);
> select name into :firstnum from dictionary.columns
> where libname="&libname" and memname="&memname" and type='num'
> having varnum=min(varnum);
> select count(*)*8 into :numlen from dictionary.columns
> where libname="&libname" and memname="&memname" and type='num';
> select nobs into :nobs from dictionary.tables
> where libname="&libname" and memname="&memname";
>quit;
>data &out;
> %if . ne &charlen %then
> array chars (&nobs) $&charlen _temporary_;;
> %if . ne &numlen %then
> array nums (&nobs) $&numlen _temporary_;;
> do __i=1 to &nobs;
> set &data;
> %if . ne &charlen %then
> chars(__i)=peekc(addr(&firstchar),&charlen);;
> %if . ne &numlen %then
> nums(__i)=peekc(addr(&firstnum),&numlen);;
> end;
> do __j=1 to 100;
> do __i=1 to &nobs;
> %if . ne &charlen %then
> call poke(chars(__i),addr(&firstchar));;
> %if . ne &numlen %then
> call poke(nums(__i),addr(&firstnum));;
> output;
> end;
> end;
> drop __:;
>run;
>%mend;
>
>You can now solve the original quest like this:
>%repeatds(data=a,out=want,n=100);
>
>Regards,
>Søren
>
>
|