LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Nov 2005 14:24:07 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: macro over letters
Comments: To: Dirk.Nachbar@DWP.GSI.GOV.UK
In-Reply-To:  <"082C44368966F001*/c=gb/admd=gold400/prmd=dss/o=departmentofsocialsecurity/ou=asd/s=Nachbar/g=Dirk/"@MHS>
Content-Type: text/plain; format=flowed

Dirk,

As a simple solution to your problem here is a example I will let you expand it to your needs:

%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 test ; %do I = 1 %to 13 ; %put macro vars Values = &&a&i ; %put dataset name = bhps.&&&a&i..indresp ; %end ; %mend ;

%test

However it is a bad design the first telling clue is the fact that the %macro definition has no parameters. But we will leave that for later.

Now if you are willing to make a slight modification I think you can get what you want easier and still stick to macro code.

%let list = a b c d e f g h i j k l m ;

%macro test ; %do I = 1 %to 13 ; %put macro vars Values = %scan(&list , &i , ' ' ) ; %put dataset name = bhps.%scan(&list , &i , ' ' )indresp ; %end ; %mend ;

%test

The macro design may very well still need some work but atleast you have easier code to read, maintain, debug. Besides the fact that you dont have to worrie about all those dots being eaten by the macro processor.

Toby Dunn

From: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK> Reply-To: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK> To: SAS-L@LISTSERV.UGA.EDU Subject: macro over letters Date: Wed, 2 Nov 2005 10:35:27 Z 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


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