Help using Base SAS procedures

CSV file with no columns names but header

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

CSV file with no columns names but header

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


Accepted Solutions
Solution
‎09-29-2014 05:31 AM
Contributor
Posts: 20

Re: CSV file with no columns names but header

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


All Replies
Super User
Super User
Posts: 7,997

Re: CSV file with no columns names but header

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;

Solution
‎09-29-2014 05:31 AM
Contributor
Posts: 20

Re: CSV file with no columns names but header

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

Super User
Super User
Posts: 7,997

Re: CSV file with no columns names but header

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.

Contributor
Posts: 20

Re: CSV file with no columns names but header

Thank you!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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