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!

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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