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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ntro
Calcite | Level 5

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

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

ntro
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ntro
Calcite | Level 5

Thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1840 views
  • 3 likes
  • 2 in conversation