BookmarkSubscribeRSS Feed
deepakkailay
Calcite | Level 5

hi,

 

I am exporting one csv file with text extension. 

exmple: 

proc export data=prog dbms=csv label outfile="1.txt" replace;
run;

 

but, I am getting variables and values with double quotes. Can we remove these double quotes?

 

I have also tried one way

filename file_1 "/location/12.txt";

data _null_;

set program;

file file_1 dlm=',';
put 'var1,var2,var3'
#2 (_all_)(:);
run;

 

but in this case, when i am opening the file, it is appearing in one line in notepad. i want the file top be show variables in first line and values in second line. can you please provide some guidance?

 

I have also used  ods csv file="//location/1.txt";
ods csv options(sheet_name="tes" flow='tables");
proc print data=programnoobs;
run;
ods csv close;

 

But again, variable and values are appearing with double quotation.

 

I need the output in below format. first line variable and second line values.

 

example:

var1,var2,var3

111,aaa,vvv

22 REPLIES 22
Jagadishkatam
Amethyst | Level 16

Please try the below code

 

proc export data=prog269_ctrl2 dbms=tab label outfile="1.txt" replace;
putnames=yes;
run;
Thanks,
Jag
deepakkailay
Calcite | Level 5

 thanks for your reply. It will not resolve the double quotes. I need the file to be have comma separated value and variables

deepakkailay
Calcite | Level 5

I need the output in this format first line variables and second line values. example:

 

var1,var2,var3

111,aaa,vvv

Jagadishkatam
Amethyst | Level 16
proc export data=prog269_ctrl2 dbms=dlm label outfile="1.txt" replace;
delimiter=',';
putnames=yes; run;

 

We can try the delimiter as above

 

Thanks,
Jag
deepakkailay
Calcite | Level 5

I want the variables to be shown as label values. but it is showing the variables labels in double quotes. how can i remove it?

Jagadishkatam
Amethyst | Level 16

We need to mention the putnames=no;

 

proc export data=prog269_ctrl2 dbms=dlm label outfile="1.txt" replace;delimiter=',';
putnames=no;
run;
Thanks,
Jag
deepakkailay
Calcite | Level 5

i am getting this message after using putname=no;

WARNING: The LABEL option will be ignored when PUTNAMES=NO.

 

also, it is creating file without variable names but i need the variable names.

Jagadishkatam
Amethyst | Level 16

This should work

 

 

proc export data=prog269_ctrl2 dbms=dlm outfile="1.txt" replace;
delimiter=','; run;
Thanks,
Jag
deepakkailay
Calcite | Level 5

Hi,

 i have used below code:


filename file_1 "location/1.txt;

data _null_;

set prior_ds;

file file_1 dlm=',';

put 'Source,val1,val2'
#2 (_all_)(:);
run;

 

it is writing the variable name i.e source,val1,val2 and the values to the same line .

can you please suggest how i can put values to second line.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use the code window - its the {i} above post area to post code:

filename file_1 "location/1.txt;

data _null_;  
  set prior_ds;
  file file_1 dlm=',';
  if _n_=1 then put 'Source,val1,val2';
  put (_all_);
run;
deepakkailay
Calcite | Level 5

put (_all_) is erroring out. If i am using _all_ then it is giving results as var1=111 .

But again, the value and variables are showing in the same line in notepad.

but I need the values and variables in separate lines.

Kurt_Bremser
Super User

@deepakkailay wrote:

put (_all_) is erroring out. If i am using _all_ then it is giving results as var1=111 .

But again, the value and variables are showing in the same line in notepad.

but I need the values and variables in separate lines.


DO NOT use notepad for the display of such datafiles. Windows notepad can't handle non-Windows text files properly.

Use notepad++ instead.

 

UNIX uses a single LF character for line breaks, while notepad expects the Windows-typical CRLF combo.

Text files from SAS UE will be in UNIX format, unless you specify a termstr=CRLF option in the file statement.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

A CSV file will have double quotes in if the data contains the delimiter, consider:

 

Somevar,Somethingelse,A line with a comma, in,something else

If that is read in the "A line with a comma, in" actually looks like two variables as the comma delimiter appears in the string.  To counteract this, SAS (and all other implementations such as Excel) will quote that string to look:

Somevar,Somethingelse,"A line with a comma, in",something else

So it is clear that the comma there is part of a text string not a delimiter.  This is standard behaviour, and if your data contains the delimiter, then that should be how it is presented.

 

deepakkailay
Calcite | Level 5

thanks,

 

but i need the output in this way:

first line variable list and second line value with comma separated. Is there a way to get this output?

 

example:

var1,var2,var3

111,aaa,vvv