SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Output SAS data into various txt files

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

Output SAS data into various txt files

I have a SAS data as attached.  I will need to input the data into three different txt files, each file contains the the data as below:

 

for file: a.dat, it has

50
12
6
3053
2.5
66.3

 

for file b.dat, it has

78.1
2.4
4
49.2
455

 

Basically, I need to create different files based on the distinct attributes in file_name.  Thank you for the help.


Accepted Solutions
Solution
‎01-11-2016 08:49 AM
Contributor
Posts: 52

Re: Output SAS data into various txt files

data want_final;

set want4;

FILE='C:\Users\output\'|| file_name || '.xls' ;

file OUT filevar=FILE mod dlm=' ';

put file_name index num;

run;

 

I used the above code.  However, ".xls" is not added into the file name.

 

If I pre-add .xls to all file name, I was albe to create all individual .xls files with different names.  However, the data of file_name, index, num are all sqeezed into one excel cell, instead of spreading into three cells in each row.

View solution in original post


All Replies
Super User
Posts: 19,770

Re: Output SAS data into various txt files

Posted in reply to wutao9999

You talk about input and output. Are you creating text files or reading text files into SAS?

Contributor
Posts: 52

Re: Output SAS data into various txt files

sorry for misleading you.  I mean output the data into txt file.  When outputting, I prefer has no attribute name outputted to the txt file, just purely the data.  Thank you.

Super User
Posts: 19,770

Re: Output SAS data into various txt files

Posted in reply to wutao9999
Use the filevar option and a put statement within a data step.

There's a lot of examples out there...

https://communities.sas.com/t5/Base-SAS-Programming/Export-CSV-File/td-p/58898
Solution
‎01-11-2016 08:49 AM
Contributor
Posts: 52

Re: Output SAS data into various txt files

data want_final;

set want4;

FILE='C:\Users\output\'|| file_name || '.xls' ;

file OUT filevar=FILE mod dlm=' ';

put file_name index num;

run;

 

I used the above code.  However, ".xls" is not added into the file name.

 

If I pre-add .xls to all file name, I was albe to create all individual .xls files with different names.  However, the data of file_name, index, num are all sqeezed into one excel cell, instead of spreading into three cells in each row.

Super User
Posts: 11,343

Re: Output SAS data into various txt files

Posted in reply to wutao9999

It is getting to be a bad idea to "lie" to Microsoft applications by naming them one way but not actually being the implied name.

You are creating a text file. If you want to open it by default in Excel then better would be to use CSV as the extention and DLM=','.  Excel doesn't treat space as a delimiter unless you go through the Excel file import wizard.

Or use Proc export to a CSV file.

Super User
Posts: 19,770

Re: Output SAS data into various txt files

Posted in reply to wutao9999

Look into ODS TAGSETS.EXCELXP or if you're on SAS 9.4 ODS EXCEL.

If you want native excel in a plain format, PROC EXPORT also works great.

If you don't have the appropriate SAS license, look into this macro.

 

http://www.sascommunity.org/wiki/A_Poor/Rich_SAS_Users_Proc_Export

Super User
Posts: 19,770

Re: Output SAS data into various txt files

Posted in reply to wutao9999

Also, the question states text file, what's with adding in Excel?  I'm not clear on what you're trying to do...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 608 views
  • 0 likes
  • 3 in conversation