SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
saraphdnz
Quartz | Level 8
%macro export_data;
%do i =1 %to 10;
proc export data=work.out_D&i.
outfile= "C:\Users\export from sas\testD&i..csv"
dbms=csv replace;
PUTNAMES=YES;
run;
%end;
%mend export_data;

Hello there - I am trying to export datasets from SAS to .csv files (a separate .csv file for each dataset) but I am not getting the results and need help to figure out the errors.

Regards,

Sara  

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

All your log is showing is that you defined the macro.

If you want to macro to generate the code to export a file you need to call the macro.

 

Add these two lines after the %MEND line.

options mprint;
%export_data;

 

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

There isn't anything wrong with your program syntax. The most likely cause is you are trying to write the CSVs to your local PC C drive when your SAS session is running on a remote SAS server. This server has no way of identifying your PC C drive. It would help if you posted your SAS log, including the errors, so we can confirm if this is what is happening or not.

saraphdnz
Quartz | Level 8

The problem is that it is not giving any errors or warnings in the log. 

My SAS installed locally and I am not using the remote server.  I think the way I call multiple files in the outfile, is not correct and causing the problem

13989  %macro export_data;
13990  %do i =1 %to 10;
13991  proc export data=work.out_D&i.
13992  outfile= "C:\Users\testD&i..csv"
13993  dbms=csv replace;
13994  PUTNAMES=YES;
13995  run;
13996  %end;
13997  %mend export_data;

 

Tom
Super User Tom
Super User

All your log is showing is that you defined the macro.

If you want to macro to generate the code to export a file you need to call the macro.

 

Add these two lines after the %MEND line.

options mprint;
%export_data;

 

saraphdnz
Quartz | Level 8
Thanks, heaps Tom, it worked.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2179 views
  • 1 like
  • 3 in conversation