Date: Wed, 14 May 2003 16:25:54 -0600
Reply-To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject: Re: Simple macro
Content-Type: text/plain; charset=us-ascii
Is there more to this problem than you're telling us? There's no need
to write a macro to generate 5 data set names if you already know the 5
A few problems stand out:
- You define NDIR and YEAR in the %MACRO line, but you don't need to.
You don't use the values that might be passed in; you immediately
overwrite them with values calculated in the macro.
- Each iteration creates a data set named dir6.temp000. The second
iteration will overwrite the data set created by the first iteration,
the third will overwrite the second, and so on. You need to (1) create
separate data sets and append them, or (b) read all the input data sets
in 1 step, not 5.
- You're creating an invalid data set name with "ir&ndir.nhds&year".
There needs to be a dot between the library name and the member name:
"dir&ndir..nhds&year". The single dot you have there now disappears
because the macro facility uses it to indicate the end of the macro
- You have an implicit data type conversion in "hosp_id_tmp =
n||'_'||&year ;". Many people think it's best to avoid those.
Since you're trying to learn, I won't give you an answer, but I'll give
you a suggestion: Create the code you need in a text editor and make
sure it works. Then convert it to a macro.
Manager, Technical Development
Metrics Department, First Health
West Sacramento, California USA
>>> David <david5705@HOTMAIL.COM> 05/14/2003 2:58 PM >>>
Starting to teach myself macro language and need some help.
Problem: Concatenate data from 5 data files:
and create new variables: "year", "hosp_id"
%macro pulldata(ndir, year) ;
%do ndir=1 %to 5 ;
%do year=1997 %to 2001 ;
data dir6.temp000 ;
set dir&ndir.nhds&year (obs=5) ;
length year $4 n $6 ;
age=input(age_tmp, 8.) ;
if age >= 18 ;
hosp_id_tmp = n||'_'||&year ;
%mend pulldata ;
I may be close, but no cigar (yet).
Thanks in advance for any help.