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.
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.
You talk about input and output. Are you creating text files or reading text files into SAS?
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.
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.
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.
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
Also, the question states text file, what's with adding in Excel? I'm not clear on what you're trying to do...
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.