BookmarkSubscribeRSS Feed
anandmgjsa
Fluorite | Level 6

Hi

My code is as below :

%macro pull_offer();

%let start_date = %sysfunc(mdy(1,1,2021));

%last_date = %sysfunc(mdy(1,5,2021));

 

%do date = &start_date to &end_date;

%let target_day = &date;

format target_day ddmmmyyyyn8.;

%put target_day;

 

proc sql inobs = 10;

create table contact as 

select * from contact_master where mis_dt = &target_day;

quit;

 

%let path = "temp/offer_data/test" || &target_day || ".csv";

%put path;

proc export data = contact;

outfile = &path;

dbms = csv;

run;

 

%end;

 

%mend pull_offer;

 

%pull_offer;

Please help!!!

14 REPLIES 14
andreas_lds
Jade | Level 19

The format statement is not valid outside of data steps and procedures. If the variable "mis_dt" is a sas date, formatting will raise other problems. If it is not a sas date, fix that issue first.

The statement

%let path = "temp/offer_data/test" || &target_day || ".csv";

won't work either, macro variable are all strings. So, you need:

%let path = temp/offer_data/test&target_day..csv;

In proc export, you need to wrap the path in quotes.

anandmgjsa
Fluorite | Level 6

Hi Still i am getting error as path= or table= statement is required and must be specified...

Kurt_Bremser
Super User

All macro programming starts with working non-macro code.

Run your SQL and EXPORT steps without any macro coding (no use of macro variables!!), and show us the complete log from that.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @anandmgjsa 

 

Outfile and dbms are both arguments to Proc Export, so don't use semicolons after first and second line.

 

proc export data = contact;
outfile = &path;
dbms = csv;
run;
anandmgjsa
Fluorite | Level 6
I have removed this ;.

But still i am getting error.
anandmgjsa
Fluorite | Level 6
I am using VDI and can not copy from that.
anandmgjsa
Fluorite | Level 6
the error is in %let path statement
anandmgjsa
Fluorite | Level 6

HI

 

I have following code:

 

anandmgjsa_0-1641977455366.png

anandmgjsa_2-1641978675493.png

I am getting sysntax error in %let path = statement

please help!!

 

Amir
PROC Star

Hi @anandmgjsa,

 

Please share the full log by copying and pasting it into a post using the "</>" (insert code) icon.

 

 

Kind regqards,

Amir.

Kurt_Bremser
Super User

Once again: START WITH WORKING NON-MACRO CODE!!!

Once that works, you can make it dynamic, but before the code works without macro coding, your efforts will be futile.

The OUTFILE= option in the PROC EXPORT statement needs a string with a physical path (enclosed in quotes) or a file reference (without quotes).

andreas_lds
Jade | Level 19

I see one problem, but that is in proc export: you need to enclose &path in quotes.

If this doesn't solve the problem, remove all macro code and solve all problem, as has be recommended by @Kurt_Bremser multiple times.

ballardw
Super User

Make sure that any sort of directory Path variable starts at a drive (Windows) or disk mount point that is accessible from the machine running SAS. If you do not start at the drive/mount level then the path is a relative and will attempt to find things relative to the current "default" location which may well be in the SAS executable folder.

 

If you have a server install then the path will be relative to the server, not your machine.

 

This in addition to the need for Outfile="&path." to properly use it in the Proc Export code.

 


@anandmgjsa wrote:

HI

 

I have following code:

 

anandmgjsa_0-1641977455366.png

anandmgjsa_2-1641978675493.png

I am getting sysntax error in %let path = statement

please help!!

 


 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 14 replies
  • 3748 views
  • 1 like
  • 6 in conversation