Maiia S.
Maiia S.

Reputation: 323

Removing Quotation Marks from Variable Names

I need to fix the output, and remove quotation marks around each attribute name:

"#var1"|"var2"|"var3"|"var5"
000|aaa|bbb|ccc
111|ddd|eee|fff

I am importing an existing .csv file, modifying it slightly, and saving as another .csv to a different location:

%let infile=/.../file.csv;
%let outfile=/.../new_file.csv;

data file_file (drop=var4);
    infile "&infile" dsd dlm=',' truncover firstobs=2;
    length var1 $10 var2 $37 var3 $100 var4 $1 var5 $13 ;
    input var1 $ var2 $ var3 $ var4 $ var5 $;
    label var1 ='#var1';
run;

proc export data = file_file 
        outfile = "&outfile" 
        label dbms=csv replace;
        delimiter='|';
run;

The output should look like:

#var1|var2|var3|var5
000|aaa|bbb|ccc
111|ddd|eee|fff

Upvotes: 1

Views: 757

Answers (1)

Tom
Tom

Reputation: 51566

You can easily do that with a simple SAS data step. You just need to know how many columns your delimited file has. Quotes around strings should be automatically removed when the values are read. To remove the fourth column just don't write it back out.

%let infile=/.../file.csv;
%let outfile=/.../new_file.csv;

data _null_ ;
  infile "&infile" dsd dlm='|' lrecl=200000 truncover ; 
  file "&outfile" dsd dlm='|' lrecl=200000 ;
  length var1-var5 $32767 ;
  input var1-var5 ;
  put (var1-var3 var5) (+0) ;
run;

Upvotes: 1

Related Questions