BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
clcl
Calcite | Level 5

I really need help with this !

i need to receive 3 files into a macro ( english comp and sat ) . i have written it but have a small problem with calling a file in a loop . you can see below . hope someone can help me please . no sure what i should put on line 1559    because "file" is part of the macro and also "i".  maybe my input is not correct ....

1555  %macro cg (file1,file2,file3);

1556  options mprint symbolgen mlogic;

1557  %do i = 1 %to &3;

1558  data cg&i;

1559  set &file&i;

1560  f&i= (x*m)/100;

1561  %end;

1562  run;

1563  %mend;

1564

1565  %cg (math, english, sat)

1 ACCEPTED SOLUTION

Accepted Solutions
KarlK
Fluorite | Level 6

If I understand correctly, you need another leading ampersand in 1559:

set &&file&i;

View solution in original post

7 REPLIES 7
KarlK
Fluorite | Level 6

If I understand correctly, you need another leading ampersand in 1559:

set &&file&i;

clcl
Calcite | Level 5


thank you it worked!!!!  could you please help me with this :

i need to receive 3 files X1 X2 and X3

trying to do it in a Marco but i have a problem with the loop and the sequence, i have tried so many differnt things ways its driving me mad ...   thanks ... CL

%macro avgofzt;

%do i=1 %to 3;

data a&i;

infile "c:\X.&i.txt";

id=1;

ERROR: Physical file does not exist, c:\X.1txt.

Linlin
Lapis Lazuli | Level 10


try changing

infile "c:\x.&i.txt";

to

infile "c:\x&i..txt";

clcl
Calcite | Level 5

THANKS IT WORKED !!!!

infile "C:\X&i..txt";

KarlK
Fluorite | Level 6

Sure. 2 dots after the &i:

infile "c:\x.&i..txt";

The 1st dot terminates macro replacement, and the second is the literal "." before the extension.

I'm glad my earlier response helped. Good luck.

clcl
Calcite | Level 5

Thanks worked ! 

Linlin
Lapis Lazuli | Level 10

data math english sat;

do x=1 to 5;

  do m=2 to 6;

  output;

  end;end;

run;

options mprint symbolgen mlogic;

%macro cg (file1,file2,file3);

%do i = 1 %to 3;

data cg&i;

set &&file&i;

f&i= (x*m)/100;

run;

%end;

%mend;

%cg (math, english, sat)

Linlin

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1108 views
  • 7 likes
  • 3 in conversation