Date: Fri, 13 Apr 2007 17:03:36 -0400
Reply-To: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Subject: Re: HELP: call execute > macro with parameters
In-Reply-To: <1176497103.426992.147140@e65g2000hsc.googlegroups.com>
Content-Type: text/plain; charset=us-ascii
> I am trying to use this sample code as a model ...
> http://support.sas.com/ctx/samples/index.jsp?sid=594&tab=code
that example is incorrect
this:
call execute('%rept('||date||','||'var1,two)');
should be
call execute('%rept('
||date
||','
||var1
||','
||two
||')'
);
I did not test the above suggestion;
there are probably note/warnings
about numeric-to-character conversion.
1. remove your call symput from the ODS csv
place the ODS csv in the macro
... hm, I'll get some argument about that suggestion
2. your macro have named parameters:
pub_name=,
pub_ID_1=
DATA _null_;
do until(EndoFile);
SET dbd.testimps end = EndoFile;
CALL EXECUTE(cats('%nrstr('
,'%get_imprints('
,'pub_name=', pub_name
,'pub_ID_1=', pub_ID_1
,')' %*close macro call;
,')' %*close nrstr;
) %*close cats;
); %*close call execute;
end;
stop;
run;%*calls executed here;
run;
review next week's paper SGF2007.113
for a discussion of why to use nrstr w/call execute
Ron Fehd the call execute(nrstr
or macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
> -----Original Message-----
> From: theorbo
> Sent: Friday, April 13, 2007 4:45 PM
> Subject: HELP: call execute > macro with parameters
>
> Hi. I am a SAS newbie so please bear with me. I have a data set
> (testimps) with two variables, pub_name and pub_ID_1. The
> first variable is character and the second numeric.
>
> I have a second data set (little_pad_hierarchy) which
> contains lots of records with many variables for each. I've
> written a macro that goes through this dataset and pulls out
> records that meet certain criteria.
>
> I want my first data set to control the parameters used for
> the macro that executes on the second data set. I want to
> execute the macro once for each record in the first dataset.
>
> I am trying to use this sample code as a model ...
> http://support.sas.com/ctx/samples/index.jsp?sid=594&tab=code
>
> I keep getting errors and I think it has to do with my non-
> understanding of the string concatenation for the macro
> parameters in the call execute portion ... any ideas? How do
> you know what to pipe and what to surround with quotes?
> Single or Double? I'm using SAS
> 9.1.3 on VMS. My code & log are below.
>
> Here is my code:
>
> DATA
> dbd.testimps;
> INFILE "ms230:[dbranning.bowker.xls]testimp.txt"
> DELIMITER="09"x TRUNCOVER DSD FIRSTOBS=2;
> INPUT pub_name :$50. pub_ID_1 :
> 20. ;
>
> RUN;
>
> %MACRO get_imprints (pub_name=,
> pub_ID_1= );
>
> DATA
> &pub_name;
> SET
> dbd.little_pad_hierarchy;
> DROP
> masterid;
> IF
> idlevel1="&pub_ID_1";
>
> RUN;
>
> PROC SORT
> DATA=&pub_name;
> BY idlevel1 idlevel2 idlevel3 idlevel4 idlevel5 idlevel6
> idlevel7 idlevel8 idlevel10;
>
> RUN;
>
> PROC PRINT
> DATA=&pub_name;
> TITLE "&pub_name imprints - from little file";
>
> RUN;
>
> %MEND
> get_imprints;
>
> ODS CSV FILE='ms230:[dbranning.bowker.xls]combined.csv'
> TYPE=csvall;
>
> /* %get_imprints (pub_name=albert_whitman, pub_ID_1=28531) */
>
> DATA _null_;
> SET dbd.testimps;
> CALL EXECUTE
> ( '%get_imprints('||"pub_name",
> ||"pub_ID_1")');
>
> RUN;
> ODS CSV CLOSE;