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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
wutao9999
Obsidian | Level 7

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

7 REPLIES 7
Reeza
Super User

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

wutao9999
Obsidian | Level 7

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.

Reeza
Super User
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
wutao9999
Obsidian | Level 7

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.

ballardw
Super User

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.

Reeza
Super User

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

Reeza
Super User

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

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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