Date: Mon, 28 Jul 1997 09:54:22 PDT
Reply-To: TWB2%Rates%FAR@BANGATE.PGE.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Tim Berryhill 3rd time <TWB2%Rates%FAR@BANGATE.PGE.COM>
Subject: Re: %LET getting macro variable value from a datastep
Steve, For the first two years, assume any macro code in a data step resolves
into plain SAS before the data step begins. Also and forever, assume the macro
language is not aware of SAS and just manipulates text which becomes your
program later. The upshot is, your %if-%then executes just once and the macro
language does not know anything about FIRST. variables.
You already got one reply explaining how to create a series of macro variables
to solve your problem. Another approach is to use the FILEVAR option of the
FILE statement. FILEVAR= specifies the name of a variable which in turn names
the output file. You might try:
DATA _NULL_;
SET BUCKS;
BY DISTRICT;
IF FIRST.DISTRICT THEN FILE DUMMY FILEVAR=DISTRICT;
PUT '"' DISTRICT '", ' NUMVAR1 ',' NUMVAR2;
RUN;
Tim Berryhill - Contract Programmer and General Wizard
TWB2@PGE.COM or http://www.aartwolf.com/twb.html
Frequently at Pacific Gas & Electric Co., San Francisco
The correlation coefficient between their views and
my postings is slightly less than 0
----------------------[Reply - Original Message]----------------------
Sent by:Steve Doig <sdoig@IMAP1.ASU.EDU>
Macro gurus:
Among the many things I don't do well in SAS is using macros, but I
think the solution to my problem is there.
My problem is that I have a dataset (BUCKS) with about 2 million
records. One of the text variables is DISTRICT, which has about 50
possible values. BUCKS is sorted by DISTRICT.
I want to subset BUCKS into 50 different comma-delimited text files,
where each file is named after the value in DISTRICT. I envision the
program to be something like this:
DATA _NULL_;
SET BUCKS;
BY DISTRICT;
%IF FIRST.DISTRICT %THEN %LET NAME=DISTRICT;
FILE &NAME;
PUT '"' DISTRICT '", ' NUMVAR1 ',' NUMVAR2;
RUN;
But I don't think macro variables actually work like this. &NAME will
resolve to DISTRICT, not to 1005 or whatever.
So, is there a neat way to do what I need to do? Thanks for any advice
you might offer.
--
*********************************************************
Stephen K. Doig, Professor, Cronkite School of Journalism,
Arizona State University, Box 871305, Tempe, AZ 85287-1305
V:602-965-0798 Fax:602-965-7041 mailto:steve.doig@asu.edu
*********************************************************
=====================================================================