Hello all,
I am trying to export a SAS table in CSV format (separator is ";") but I need to obtain a file where the 1st line will contain some information such as date, version,... and starting row 2 the data itself without the columns names.
The closest I could get is using the following code:
DATA survey;
INPUT id sex $ age inc r1 r2 r3 ;
DATALINES;
1 F 35 17 7 2 2
17 M 50 14 5 5 3
33 F 45 6 7 2 7
;
RUN;
ods csvall file=C:\myfile.csv' options(delimiter=';');;
proc print data=survey noobs label;
title "29/09/2014;version #3";
run;
ods csvall close;
Then I end up with:
29/09/2014;version #3
"id";"sex";"age";"inc";"r1";"r2";"r3"
1;"F";35;17;7;2;2
17;"M";50;14;5;5;3
33;"F";45;6;7;2;7
49;"M";24;14;7;5;7
65;"F";52;9;4;7;7
81;"M";44;11;7;7;7
2;"F";34;17;6;5;3
18;"M";40;14;7;5;2
34;"F";47;6;6;5;6
50;"M";35;17;5;7;5
Problem is that I have a blank line and that columns names are still there. I wish to get:
29/09/2014;version #3
1;"F";35;17;7;2;2
17;"M";50;14;5;5;3
33;"F";45;6;7;2;7
49;"M";24;14;7;5;7
65;"F";52;9;4;7;7
81;"M";44;11;7;7;7
2;"F";34;17;6;5;3
18;"M";40;14;7;5;2
34;"F";47;6;6;5;6
50;"M";35;17;5;7;5
Any help very much apreciated!
Nicolas
Thank you RW9. Sorry for the typo. I modified the path when editing the code here and missed the opening quote.
This is the format needed to load the data back into a custom datawarehouse so not my choice!
Your solution is working and I'm fine with it but is there any other possibility that concatening the variables as I have many.
Thanks again
Hi,
Well, first off you have typos in that code. Secondly, if you are talking about a file which does not conform to the format of:
<HEADER>,<HEADER>... (optional)
<DATA>,<DATA>...
Then its not a delimited file, but a custom format of your own. You also don't want to "print" a file like that.
So, if you really want a file that looks like that (not my recommendation) do:
data _null_;
set survey;
file "s:\temp\rob\myfile.csv";
if _n_=1 then put "29/09/2014;version #3";
else do;
tmp=strip(put(id,best.))||';"'||strip(sex)||'";'||strip(put(age,best.))||';'||strip(put(inc,best.))||';'||strip(put(r1,best.))||';'||strip(put(r2,best.))||';'||strip(put(r3,best.));
put tmp;
end;
run;
Thank you RW9. Sorry for the typo. I modified the path when editing the code here and missed the opening quote.
This is the format needed to load the data back into a custom datawarehouse so not my choice!
Your solution is working and I'm fine with it but is there any other possibility that concatening the variables as I have many.
Thanks again
Yes, sure. Check out this post:
https://communities.sas.com/message/184971#184971
Look at Tom's suggestion second to last post, select the variables/formats into a macro from the sas variables tables. You can also put dlm=";" on your file statement to get delimiters as well.
Thank you!
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.