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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.