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 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 8 Nov 2007 12:36:48 -0500
Reply-To:     Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:      Re: feeding macro from a file
Comments: To: tanwanzang@YAHOO.COM

On Thu, 8 Nov 2007 15:35:17 -0000, tanwan <tanwanzang@YAHOO.COM> wrote:

>%macro IMPCSV; >options mprint; >proc sql noprint; > select count(*) into :limit from TOIMP; > %let limit=&limit; > select x into :x1 - :x&limit from TOIMP; > select y into :y1 - :y&limit from TOIMP; > >quit; > >%do loop = 1 %to &limit; >proc import datafile="E:\dados planb\Planb\Producao\&&x&loop...csv" > out=planb.y&loop > dbms=csv > replace; > getnames=yes; >%end; >run; >%mend IMPCSV; > >%IMPCSV;

hi, "feeding macro from a dataset var" seems to be a common task. there are many ways to do this. Here are two common and one un-common ways. hth. cheers, chang

%*-- something to do for each child --*; %macro shout(myName=); %put NOTE: my name is &myName.!; %mend shout;

%*-- check --*; %shout(myName=chang) /* on log NOTE: my name is chang! */

%*-- method1: call execute --*; data _null_; set sashelp.class; length macro $200.; macro = catt('%shout(myName=', name, ')'); call execute(macro); run;

%*-- method2: looping with a list --*; proc sql noprint; select name into :children separated by " " from sashelp.class; quit;

%macro cacophony(from=); %local i name; %let i = 1; %let name = %scan(&from., &i.); %do %while (&name.^=); %shout(myName=&name.) %let i = %eval(&i. + 1); %let name = %scan(&from., &i.); %end; %mend cacophony; %cacophony(from=&children.)

%*-- method3: using a simple utility macro --*; filename over url "http://changchung.com/download.php?filename=over.sas"; %inc over/source2; filename over clear;

%over(sashelp.class, do=%nrstr( %shout(myName=%getvar(name)) )) /* on log NOTE: my name is Alfred! NOTE: my name is Alice! NOTE: my name is Barbara! NOTE: my name is Carol! NOTE: my name is Henry! NOTE: my name is James! NOTE: my name is Jane! NOTE: my name is Janet! NOTE: my name is Jeffrey! NOTE: my name is John! NOTE: my name is Joyce! NOTE: my name is Judy! NOTE: my name is Louise! NOTE: my name is Mary! NOTE: my name is Philip! NOTE: my name is Robert! NOTE: my name is Ronald! NOTE: my name is Thomas! NOTE: my name is William! */


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