Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro do loop help

Status
Not open for further replies.

bumed

Technical User
Aug 23, 2007
18
US
Ok I have set a Macro Dpull and It works fine. Now I'm setting up a macro Drun. Drum is supposed to take a list of file names from a txt document and then use that list in place of fname in the Dpull macro. But I cant seem to get it to work. Hopefully you can help thank you all. Here is the code.


%macro Dpull (fname);
data A_&fname;
infile "\\Ad.bu.edu\dfs\bumc\BUSM\Anatomy and Neurobiology\Dept\LDCN\Autism\U-19 2002-2007\Wave3_PII\Production study\
Face Coding - Noldus\Noldus\The Observer\Workspaces\Projects\testing face coding2\Data Files cleaned\&fname..odf" firstobs= 13;
input time code $;
run;
Data B_&fname;
set A_&fname;
if code = "neutral" then emotion2=1;
if code = "angry" then emotion2=2;
if code = "happy" then emotion2=3;
if code = "surprise" then emotion2=4;
if code = "fear" then emotion2=5;
if code = "other" then emotion2=6;

if code = "flat" then expressiveness2=1;
if code = "mild" then expressiveness2=2;
if code = "moderate" then expressiveness2=3;
if code = "extreme" then expressiveness2=4;

if code = "fully" then naturaleness2=1;
if code = "slightly" then naturaleness2=2;
if code = "very" then naturaleness2=3;
if code = "unnatural" then naturaleness2=4;

if code = "on" then gaze2=1;
if code = "away" then gaze2=2;

data C_&fname;
set B_&fname;
emotion = lag3(emotion2);
expressiveness = lag2(expressiveness2);
naturaleness = lag(naturaleness2);
gaze = gaze2;

data D_&fname;
set C_&fname (keep = emotion expressiveness naturaleness gaze time);
if gaze = "." then delete;
Emot = time||"_Emot";
Expr = time||"_Expr";
Natu = time||"_Natu";
Gaz1 = time||"_Gaze";

Proc transpose data = D_&fname out = Emot_&fname;
ID Emot;
var emotion;
Proc transpose data = D_&fname out = Expr_&fname;
ID Expr;
var expressiveness;
Proc transpose data = D_&fname out = Natu_&fname;
ID Natu;
var naturaleness;
Proc transpose data = D_&fname out = Gaz1_&fname;
ID Gaz1;
var gaze;

Data E_&fname;
merge Emot_&fname Expr_&fname Natu_&fname Gaz1_&fname;
run;

data AA_&fname;
infile "\\Ad.bu.edu\dfs\bumc\BUSM\Anatomy and Neurobiology\Dept\LDCN\Autism\U-19 2002-2007\Wave3_PII\Production study\
Face Coding - Noldus\Noldus\The Observer\Workspaces\Projects\testing face coding2\Data Files cleaned\&fname..odf" firstobs=11;
input coder $;
run;

data AB_&fname;
Set AA_&fname (obs = 1);

data BA_&fname;
infile "\\Ad.bu.edu\dfs\bumc\BUSM\Anatomy and Neurobiology\Dept\LDCN\Autism\U-19 2002-2007\Wave3_PII\Production study\
Face Coding - Noldus\Noldus\The Observer\Workspaces\Projects\testing face coding2\Data Files cleaned\&fname..odf" firstobs=7;
input sub $1-69;
run;

data BB_&fname;
Set BA_&fname (obs = 1);
SubID=substr(sub,63,7);

data BC_&fname;
Set BB_&fname (Drop= sub);

data CA_&fname;
infile "\\Ad.bu.edu\dfs\bumc\BUSM\Anatomy and Neurobiology\Dept\LDCN\Autism\U-19 2002-2007\Wave3_PII\Production study\
Face Coding - Noldus\Noldus\The Observer\Workspaces\Projects\testing face coding2\Data Files cleaned\&fname..odf" firstobs=7;
input @'.01_'AVI $;
run;

data F_&fname;
Set BC_&fname;
Set AB_&fname;
Set CA_&fname;
Set E_&fname (drop=_name_);

proc print data = F_&fname;
run;

%mend Dpull;

%macro Drun;
data AA;
infile "C:\Documents and Settings\boraste\Desktop\Data File list of names.txt";
input FileN $ @@;
run;

data _null_;
set AA;
call symput("FileN2",FileN);
run;

/*** NOW CALL YOUR MACRO DPULL ***/
%do i=1 %to 892;
%Dpull(&FileN2);
%end;
mend Drun;
 
Your &FILEN2 macro variable will only have the last file name in your list. (You reset that macro var every time you read in a record in your dataset AA.)

(I would also like to point out that you seem to have a problem using the RUN statement. Each data and proc step should have a matching RUN statement for clean code.)

your code
Code:
%macro Drun;
data AA;
infile "C:\Documents and Settings\boraste\Desktop\Data File list of names.txt";
input FileN $ @@;
run;

data _null_;
  set AA;
  call symput("FileN2",FileN);
run;

/*** NOW CALL YOUR MACRO DPULL ***/
%do i=1 %to 892;
  %Dpull(&FileN2);
%end;
mend Drun;

Here is how I would fix it.
Code:
%macro Drun;
data AA;
infile "C:\Documents and Settings\boraste\Desktop\Data File list of names.txt";
input FileN $ @@;
run;

data _null_;
  set AA end=last;
  call symput("FileN"||trim(left(put(_n_,8.))),FileN);
  if last then
   call symput('limit', trim(left(put(_n_,8.))) );
run;

/*** NOW CALL YOUR MACRO DPULL ***/
%do i=1 %to &limit;
  %Dpull(&&FileN&i);
%end;
%mend Drun;


Hope this helps.
 
Thank for the run info. I'm still learning, self taught. The problem is that there is now no output, it run without errors but shouldn't it be doing the proc print each time? Because I was going to take each output from the macros and merge then into one large file.
Thanks for the help
 
I got it. Thanks so much for your help. This site is a god sent.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top