date extraction

  • Follow


Hi I want to extract each date from Qdates get the data corresponding
to that date from all dataset and output it
to a file with a sheet named according to the date. I am a bit stuck
on how to do this below is what i am trying.
Thanks for all your help


%let Qdates = ('29-Apr-2005', '30-Jun-2005', '30-Sep-2005');


%macro extractdate;

%do %while(i<=3);
data tmp;
set all;
if date = Qdates(i);
run;

PROC EXPORT DATA= tmp
             OUTFILE= "C:\temp.xls"
              DBMS=EXCEL REPLACE;
       SHEET=Qdates(i);
RUN;

%let i = &i+1;
%end;

%mend;
0
Reply hd 12/13/2010 8:54:29 PM

On Dec 13, 12:54=A0pm, hd <heen...@gmail.com> wrote:
> Hi I want to extract each date from Qdates get the data corresponding
> to that date from all dataset and output it
> to a file with a sheet named according to the date. I am a bit stuck
> on how to do this below is what i am trying.
> Thanks for all your help
>
> %let Qdates =3D ('29-Apr-2005', '30-Jun-2005', '30-Sep-2005');
>
> %macro extractdate;
>
> %do %while(i<=3D3);
> data tmp;
> set all;
> if date =3D Qdates(i);
> run;
>
> PROC EXPORT DATA=3D tmp
> =A0 =A0 =A0 =A0 =A0 =A0 =A0OUTFILE=3D "C:\temp.xls"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 DBMS=3DEXCEL REPLACE;
> =A0 =A0 =A0 =A0SHEET=3DQdates(i);
> RUN;
>
> %let i =3D &i+1;
> %end;
>
> %mend;

I didn't know that you could access a macro variable list like an
array...

it doesn't work for me, ie %put &qdates(i) doesn't return the i'th
variable in the list.

This does however:
%let Qdates =3D ('29Apr2005'd '30Jun2005'd '30Sep2005'd);

%put &qdates;

%put %scan(&qdates,1);

HTH,
Reeza
0
Reply Reeza 12/13/2010 10:54:30 PM



>"hd"  wrote in message 
>news:7f960f4d-9dae-4706-a130-f90f1468b1ff@p11g2000vbn.googlegroups.com...


>Hi I want to extract each date from Qdates get the data corresponding
>to that date from all dataset and output it
>to a file with a sheet named according to the date. I am a bit stuck
>on how to do this below is what i am trying.
>Thanks for all your help


>%let Qdates = ('29-Apr-2005', '30-Jun-2005', '30-Sep-2005');


>%macro extractdate;

>%do %while(i<=3);
>data tmp;
>set all;
>if date = Qdates(i);
>run;

>PROC EXPORT DATA= tmp
>             OUTFILE= "C:\temp.xls"
>              DBMS=EXCEL REPLACE;
>       SHEET=Qdates(i);
>RUN;

>%let i = &i+1;
>%end;

>%mend;

Your program is wrong in so many aspects.  First of all, who told you that 
&Qdate is an array?  Second of all, %let is a string statement so

>%let i = &i+1;

will give you,  instead of i = 2, you'd have i equals to "1+1" so nothing 
makes sense.

Why don't you just process one date at a time and pass the date value into 
the macro function?  Then all you have to do is call the macro three times?

Finally, SAS date constant is in the format "29Apr2005"d.  I don't know your 
data so I have no ideas whether you are storing the dates as a string or as 
numeric. 

0
Reply Kenneth 12/14/2010 12:53:43 AM

I am thinking you can use the table of Qdate list LEFT JOIN the other
table.
0
Reply palapara 12/14/2010 4:17:00 PM

3 Replies
266 Views

(page loaded in 0.049 seconds)

Similiar Articles:













7/25/2012 11:58:44 PM


Reply: