BookmarkSubscribeRSS Feed
ramanandyadav
Fluorite | Level 6

Hi Everyone,

 

I am working EG and i'm trying to pass one csv file to the macro but it is not working Here is my code below.

 

 


%MACRO Operation(MyFile)
DATA WORK."&MyFile"; *file name should come without extension;
LENGTH
Name $ 100
MOBNO $ 20
PhoneNo $ 20
STATE $ 100
CITY $ 100

FORMAT
Name $CHAR100.
MOBNO $CHAR20.
PhoneNo $CHAR20.
STATE $CHAR100.
CITY $CHAR100.


INFORMAT
Name $CHAR100.
MOBNO $CHAR20.
PhoneNo $CHAR20.
STATE $CHAR100.
CITY $CHAR100.

INFILE '/sas/FLATFILES/LEAD/"&MyFile"' * Path of the file should come with extension;
/* LRECL=499
ENCODING="UTF-8"
TERMSTR=CRLF */
DLM='|'
MISSOVER
DSD
FIRSTOBS=2;
INPUT
Name : $CHAR100.
MOBNO : $CHAR20.
PhoneNo : $CHAR20.
STATE : $CHAR100.
CITY : $CHAR100.

RUN;
%MEND;

%Operation("MyFile.csv");

 

 

please if you have any suggestion

1 REPLY 1
TomKari
Onyx | Level 15

First problem: you need a semicolon at the end of the %macro statement.

 

%MACRO Operation(MyFile);

 

Second problem: Too many double quotes. Changing these lines as shown will work.

 

DATA WORK.&MyFile; *file name should come without extension;

INFILE '/sas/FLATFILES/LEAD/&MyFile' * Path of the file should come with extension;

%Operation(MyFile.csv);

 

Third problem: In line

 

DATA WORK.&MyFile; *file name should come without extension;

 

&Myfile is resolving to testfile.txt, which means that your SAS dataset name is work.testfile.txt, which is illegal. Easiest solution is add another macro parameter for the SAS file name:

 

%MACRO Operation(MyFile, MySASFile);

DATA WORK.&MySASFile; *file name should come without extension;

%Operation(MyFile.csv, MyFile);

 

Fourth problem: You need to use double quotes for macro variables to resolve:

 

INFILE "/sas/FLATFILES/LEAD/&MyFile" * Path of the file should come with extension;

 

Fifth problem: Your comment on the INFILE statement is before the semicolon, so it's being picked up as SAS code. You should remove it, or put it after the semicolon:

 

INFILE "/sas/FLATFILES/LEAD/&MyFile"

 

This should move the yardstick for you.

 

Tom

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 982 views
  • 0 likes
  • 2 in conversation