|
I would probably do:
%let list = a b c d e f g h i j k l m;
and scan it as I posted earlier today:
%macro loop(list);
%local word;
%let i=1;
%let word = %scan(&list,&i,%str( ));
%do %while (&word ne );
%* your code. you could even have a nested macro: ;
%code
%let i=%eval(&i+1);
%let word = %scan(&list,&i,%str( ));
%end;
%mend;
For example:
%macro code;
%put &word;
%mend;
%loop(&list)
Your code below won't work because the macro variables:
&iindresp
&ihid
&ipno
&iage
&ijbpenm
etc.
don't exist. Do you see how SAS would parse that code? It sees the
ampersand, and would look for the next word boundary. How would SAS know
that you mean &i + your_text and not &your_text?
You need a dot to signal the end of the macro variable:
&i.indresp
&i.hid
&i.pno
&i.age
&i.jbpenm
and two dots if you actually need a single dot. Read the doc for more
details on this syntax.
But again, instead of &a1, &a2, etc, I would code it as I did above.
Hope this helps,
Scott
"Dirk Nachbar" <Dirk.Nachbar@DWP.GSI.GOV.UK> wrote in message
news:"082C44368966F001*/c=gb/admd=gold400/prmd=dss/o=departmentofsocialsecurity/ou=asd/s=Nachbar/g=Dirk/"@MHS...
> Dear all
>
> I have 13 datasets which start with a different letter a-m. I want to do a
> macro for all 13 of them but I am unsure about the syntax.
> the begging should be
>
> data pena;
> set bhps.aindresp (keep=ahid...)
>
> help would be appreciated
>
> %let a1=a;
> %let a2=b;
> %let a3=c;
> %let a4=d;
> %let a5=e;
> %let a6=f;
> %let a7=g;
> %let a8=h;
> %let a9=i;
> %let a10=j;
> %let a11=k;
> %let a12=l;
> %let a13=m;
>
> %macro bhps;
> %do i=1 %to 13;
> data pen&&a&i;
> set bhps.&&a&iindresp (keep=&&a&ihid &&a&ipno &&a&iage &&a&ijbpenm
> &&a&iage &&a&iQFACHI);
> where &&a&iage ge 16 and &&a&iage < 65;
> member=0;
> if &&a&ijbpenm=1 then member=1;
> edu=0;
> if &&a&iqfachi=1 or &&a&iqfachi=2 or &&a&iqfachi=3 then edu=1;
> year=&i;
> run;
> data sex&&a&i;
> set bhps.&&a&iindall (keep= &&a&ihid &&a&ipno &&a&ihgsex);
> id=&&a&ihid*10+&&a&ipno;
> drop &&a&ihid &&a&ipno;
> run;
> proc sort data=pen&&a&i;
> by id;
> run;
> proc sort data=sex&&a&i;
> by id;
> run;
> data pen&&a&i;
> merge pen&&a&i (in=a) sex&&a&i;
> by id;
> if a;
> run;
> proc sort data=pen&&a&i;
> by &&a&iage edu;
> run;
> %end;
> %mend;
> %bhps;
>
>
> Dirk Nachbar
> Assistant Economist
> Pensim2
> Department for Work and Pensions
> Level 4, The Adelphi
> 1-11 John Adam St
> WC2N 6HT London
> 020 796 28531
> **********************************************************************
> This document is strictly confidential and is intended only for use by the
> addressee.
> If you are not the intended recipient, any disclosure, copying,
> distribution or other
> action taken in reliance of the information contained in this e-mail is
> strictly prohibited.
> Any views expressed by the sender of this message are not necessarily
> those of the Department
> for Work and Pensions.
> If you have received this transmission in error, please use the reply
> function to tell us
> and then permanently delete what you have received.
> Please note: Incoming and outgoing e-mail messages are routinely monitored
> for compliance
> with our policy on the use of electronic communications.
> **********************************************************************
>
>
>
> The original of this email was scanned for viruses by the Government
> Secure Intranet (GSi) virus scanning service supplied exclusively by
> Energis in partnership with MessageLabs.
>
> On leaving the GSi this email was certified virus-free
|