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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 1 reply
  • 617 views
  • 0 likes
  • 2 in conversation