Hello there,
I want to export a sas file as csv file in the latest SAS EG Version.
The table has 4 columns (number, charc, date1, date2).[number as int, charc as character, date1&date2 as date]
The charc-column contains numbers from 0 to 20 (1,2,3,...,10,...15,...20) and as the table needs to the same logical record length for every row for further processing, I wanted to export all one digit numbers as 'blankNUMBER', e.g: blank0, blank1, blank2, and so on.
Number;Charc;Date1;Date2
123456; 0;2019-01:2019-02
....
123456;10;2019-01;2019-02
proc sql;
create table TABLE_1 as
select number,
case when charc lt 10 then cat(' ',charc)
else put(charc,2.)
end as charc,
date1,
date2
from TABLE_2;
quit;
filename csv "path...TABLE_1_Export.csv";
data _null_;
set TABLE_1;
file csv dlm=';';
if _n_ eq 1 then
PUT @1 'number;charc;date1;date2';
PUT number :$10.
charc :$char2.
date1 :EURDFDD10.
date2 :EURDFDD10.;
run;
Unfortunately, the blank in the cat-function is not visible in the output. However, when I change the blank to a tab (by using '09'x I think) it's working, but a tabulator does not work for me.
Are single blanks not possible to process while exporting to csv or am I missing sth. important in my code.
Thanks in advance and have a great day,
Lukas
Please show examples of the type of file you want to create. Make sure to use the Insert Code button on the editor menu so you get a pop-up box to paste in the example lines and they will not get mangled by the Forum software.
A delimited file (like a CSV file or the semi-colon delimited file in your quesiton) should NOT have fixed length records (or fixed length fields). That is just the nature of the beast. Note that normal readers of CSV files will ignore the leading/trailing spaces in the values anyway. SAS will definitely do that.
Perhaps you just want to create a fixed column file and stuff in some commas (or semi-colons)?
Perhaps something like this in a DATA step?
put Number 6. ';' Charc $char2. ';' Date1 EURDFDD10. ';' Date2 EURDFDD10. ;
Why does you example line show only 7 characters for the dates if you want to use a format with a width of 10?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.