Date: Wed, 11 Dec 2002 11:45:28 -0500
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: Macro inside a macro
Content-Type: text/plain; charset="iso-8859-1"
Doug,
Yes, in fact that is the intended purpose of CALL SYMPUT - communication of
data information in one step to code in another.
However, your code probably indicates some misunderstanding with SAS. There
is no need to create a SAS data set just because you have a DATA step.
There is no need to read all datasets with a BY statement. CALL SYMPUT will
execute each time the IF condition passes. Probably there is only one ID
with value 2, but if not it becomes a question of which one you want. In
the code below I will take the first. There is no need to read all the data
for just one record. The variable, QUESTIONABLE_VAR, will not be created
when the IF condition always fails, so it is a good idea to initialize it.
Taking all of this into account and assuming it is relevant to your problem,
I would write the first step as:
%let questionable_var = problem ;
DATA _null_ ;
SET &SOMEDATASET;
where ID = 2 ;
CALL SYMPUT ('QUESTIONABLE_VAR',NAME);
stop ;
RUN;
The second step as written assigns the same value to NEWID for all records
regardless of any other values on the records. This is very suspicious and
suggests that you may not be getting the important information, with a
simple yes. If you explain your problem, someone will probably give you
better advice and decide whether CALL SYMPUT is really the best tool for the
problem.
IanWhitlock@westat.com
-----Original Message-----
From: Cacialli, Doug [mailto:Doug_Cacialli@URMC.ROCHESTER.EDU]
Sent: Wednesday, December 11, 2002 10:36 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Macro inside a macro
Y'all,
Can somebody tell me, as simply as possible, if it is possible to use CALL
SYMPUT and the resulting macro variable, within a macro. For example (this
is a gross oversimplification of what I'm attempting to do):
%MACRO EXAMPLE (SOMEDATASET=);
DATA EXAMPLE;
SET &SOMEDATASET;
BY ID;
IF ID = 2 THEN CALL SYMPUT ('QUESTIONABLE_VAR',NAME);
RUN;
DATA EXAMPLE2;
SET IDLIST;
BY ID;
NEWID = &QUESTIONABLE_VAR;
RUN;
%MEND EXAMPLE;
Would that work? I'd be grateful for any help. Thanks.
Doug out.
---------------------------------------------------
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309 Fax: (585)506-0287
**** NOTE NEW FAX NUMBER ****
---------------------------------------------------