BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
esita
Calcite | Level 5

Hi,

I'm trying to convert SAS files into text files and I have 120 of them. Can anyone help me figure out what wrong did I do. Appreciate your help

Thanks,

Esita

libname rna "C:\data";

%macro export_data (file=,textfile=);

proc export data=&file.

outfile="&textfile."

dbms= tab replace;

run;

%mend export_data;

%export_data (file= C:\data\cell_one.sas7bdat, textfile= rna.cell_one.txt);

%export_data (file= C:\data\cell_two.sas7bdat, textfile= rna.cell_two.txt);

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you are naming the output based on the input and sending it all to the same folder you can simplify a bit:

libname rna "C:\data";

%macro export_data (file=);

proc export data=ma.&file.

outfile="C:\folder\subfolder\&file..txt"

dbms= tab replace;

run;

%mend export_data;

Better practice though would be to provide  library and path as parameters to make it more flexible. But if this is a one time use that may not be critical.

View solution in original post

7 REPLIES 7
Anotherdream
Quartz | Level 8

I think there might be a few things wrong here. Off the top of my head, your textfile doesn't have an output path. Therefore your code for the first run will look like follows.

proc export data=C:\data\cell_one.sas7bdat   outfile="rna.cell_one.txt" dbms=tab replace;

run;

Note how the outfie doesn't have a specific output path location to output your file?  Try fixing that first.

Secondly, it looks like you are trying to export a sas Dataset found on your C:\data drive.  The problem is I don't think proc export allows you to use a file reference for a sas dataset. you actually need to use a named sas Dataset in your code, which you do not have... Don't quote me on this as I've actually never tried it and don't have sas in front of me right now.... However do this.

libname mylib 'c:\data';

proc export data=mylib.Cell_one outfile="c:\your output path\rna.cell_one.txt" dbms=tab replace;

run;

Reeza
Super User

You actually can reference a sas dataset with it's path...but I'd recommend your solution overall. 

I'd bet if you searched through the forums you'd find several solutions to your problem, in fact, they would automatically call all files in that particular library.

ballardw
Super User

If you are naming the output based on the input and sending it all to the same folder you can simplify a bit:

libname rna "C:\data";

%macro export_data (file=);

proc export data=ma.&file.

outfile="C:\folder\subfolder\&file..txt"

dbms= tab replace;

run;

%mend export_data;

Better practice though would be to provide  library and path as parameters to make it more flexible. But if this is a one time use that may not be critical.

Tom
Super User Tom
Super User

If you turn on MPRINT option and just run one of the macro calls you should see the problem for yourself very quickly.

MPRINT(EXPORT_DATA):   proc export data=C:\data\cell_one.sas7bdat outfile="rna.cell_one.txt" dbms= tab replace;

NOTE: The SAS System stopped processing this step because of errors.

MPRINT(EXPORT_DATA):   run;

NOTE: Line generated by the macro variable "FILE".

1    C:\data\cell_one.sas7bdat

      -

      22

      200

ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATA, DBLABEL, DBMS, DEBUG, FILE, LABEL, OUTFILE, OUTTABLE,

              REPLACE, TABLE, _DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

You are passing in the SAS dataset by filename rather than using the libref MA that you defined in the first line of your program. So either change the first value passed to the macro to be a SAS dataset reference like MA.CELL_ONE or remove the LIBREF and put quotes around the physical filename "C:\data\cell_one.sas7bdat" and SAS will make a temporary libref for your automatically.

You also might want to include a fully qualified path for the output file, otherwise it will be created in whatever directory is current when the code is run. c:\data\rna.cell_one.txt

esita
Calcite | Level 5

Thank you all for your suggestions. This is what I tried. And I got error msg "ERROR: Export unsuccessful.  See SAS Log for details."

libname rna "C:\data";

%macro export_data (file=);

proc export data=rna.&file.

outfile="rna.&file.txt"

dbms= tab replace;

run;

%mend export_data;

%export_data (file= cell_one);

%export_data (file= cell_two);

esita
Calcite | Level 5

And I tried this as well. both give me the same error

libname rna "C:\data";

%macro export_data (file=);

proc export data=rna.&file.

outfile="C:\data.&file.txt"

dbms= tab replace;

run;

%mend export_data;

%export_data (file= cell_one);

%export_data (file= cell_two);

ballardw
Super User

outfile="C:\data.&file.txt"

should be

outfile="C:\data\&file..txt"

outfile="C:\data.&file.txt" would resolve to outfile="C:\data<file>txt" and would be 1) just a folder and 2) likely one you don't have.

The first period after the &file says to append the text to the macro variable value, the second one is to comply with windows naming conventions of .extension.

You should post the error when you get one but I'm pretty sure it was a file or folder not found.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 7 replies
  • 7581 views
  • 1 like
  • 5 in conversation