<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: single quote working similar to double quotes in dsd option in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946656#M370719</link>
    <description>&lt;P&gt;I see no issue here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dsd dlm="|" truncover;
input
  f1 :$10.
  f2 :$10.
  f3 :$10.
;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|30
;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;f1	f2	f3
a	b	c
 	 	 
 	d	e
'	f	g
h	'	i
 	'	2023-12-12
&lt;/PRE&gt;
&lt;P&gt;As you can see, the single quote is read as data and has no special meaning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get different results, post examples of the csv file which causes this behavior, and the complete code you ran against it.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Oct 2024 12:02:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-10-08T12:02:06Z</dc:date>
    <item>
      <title>single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946649#M370715</link>
      <description>&lt;P&gt;I have to read a csv file and produce sas dataset&lt;/P&gt;
&lt;P&gt;When I am trying to read it ,single quote is behaving similar to double quote and all the data in other fields&amp;nbsp; after single quote is read as one value. How can I fix it?&lt;/P&gt;
&lt;P&gt;Please dont ask me why data in a field&amp;nbsp; has only single quote. It is some encrypted field. I cannot alter source data in any way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code and data:&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;infile inf delimiter = '|' missover dsd lrecl=32767 firstobs=2;&lt;/P&gt;
&lt;P&gt;followed by informat format and input statements&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input csv file has data like this |'|2023-12-12|30|40||||||DENG|&lt;/P&gt;
&lt;P&gt;Now output dataset is taking all the above values in single field "crys_id_local" instead of multiple fields. sample output&lt;/P&gt;
&lt;P&gt;crys_id_local&lt;/P&gt;
&lt;P&gt;============&lt;/P&gt;
&lt;P&gt;|2023-12-12|30|40||||||DENG|&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 11:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946649#M370715</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2024-10-08T11:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946651#M370717</link>
      <description>&lt;P&gt;Think you need to specify som input fields.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data my_data;
    infile inf delimiter='|' missover dsd;
    input field1 : $10.
          date   : yymmdd10.
          value1 : 8.
          value2 : 8.
          field5 : $10.
          field6 : $10.
          field7 : $10.
          field8 : $10.
          field9 : $10.
          field10: $10.
          field11: $10.;
    format date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Oct 2024 11:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946651#M370717</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2024-10-08T11:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946654#M370718</link>
      <description>&lt;P&gt;filed names are provided with each informat format and format statements&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 12:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946654#M370718</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2024-10-08T12:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946656#M370719</link>
      <description>&lt;P&gt;I see no issue here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dsd dlm="|" truncover;
input
  f1 :$10.
  f2 :$10.
  f3 :$10.
;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|30
;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;f1	f2	f3
a	b	c
 	 	 
 	d	e
'	f	g
h	'	i
 	'	2023-12-12
&lt;/PRE&gt;
&lt;P&gt;As you can see, the single quote is read as data and has no special meaning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get different results, post examples of the csv file which causes this behavior, and the complete code you ran against it.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 12:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946656#M370719</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-08T12:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946661#M370722</link>
      <description>&lt;P&gt;That is know behavior of DSD processing in SAS.&lt;/P&gt;
&lt;P&gt;Not for the example you showed, since it only has one single quote on the line.&amp;nbsp; But if you had TWO single quotes. One at the START of a value and another later at the END of a value then the combination will be treated as one long quoted value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's add a second single quote to your example&lt;/P&gt;
&lt;PRE&gt;|'|2023-12-12|30|40||||'||DENG|&lt;/PRE&gt;
&lt;P&gt;Now you have 5 fields instead of 12 fields.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var1=''
var2='|2023-12-12|30|40||||'
var3=''
var4='DENG'
var5=''&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will need to either parse the string yourself.&lt;/P&gt;
&lt;P&gt;Or run some preprocessing to convert the single quotes into quoted single quotes.&amp;nbsp; So if the string looked like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;|"'"|2023-12-12|30|40||||"'"||DENG|&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then SAS will read it as 12 fields with the second and ninth as being strings consisting of just a single quote.&lt;/P&gt;
&lt;P&gt;So change your code to instead be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   infile inf dsd dlm= '|' truncover lrecl=32767 firstobs=2;
   input @;
   _infile_ = tranwrd(_infile_,"|'|",'|"''"|');
...
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note:&amp;nbsp; Most variables will not need to have either formats or informats attached to them.&amp;nbsp; So in general it is better to use a LENGTH statement to define the variables and only add FORMAT and/or INFORMAT statements for the variables (like DATE values) that will need them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 12:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946661#M370722</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-08T12:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946673#M370723</link>
      <description>&lt;P&gt;Please add another value with single quote and try ..It adds as ending single quote and everything in between will be considerd as one column value.Please check last record in below example.I have modified&amp;nbsp; it&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data want;
infile datalines dsd dlm="|" truncover;
input
  f1 :$10.
  f2 :$10.
  f3 :$10.
;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|'
;

proc print data=want noobs;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 14:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946673#M370723</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2024-10-08T14:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946685#M370726</link>
      <description>&lt;P&gt;Can you please help me place the _infile_ line. It is not working as expected in below code.&lt;/P&gt;
&lt;P&gt;I have tried with csv file as well instead of datalines.It did not work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;infile datalines dsd dlm="|" truncover;&lt;BR /&gt;input&lt;BR /&gt;f1 :$10.&lt;BR /&gt;f2 :$10.&lt;BR /&gt;f3 :$10.&lt;BR /&gt;;&lt;BR /&gt;_infile_ = tranwrd(_infile_,"|'|",'|"''"|');&lt;BR /&gt;datalines;&lt;BR /&gt;a|b|c&lt;BR /&gt;|||&lt;BR /&gt;|d|e&lt;BR /&gt;'|f|g&lt;BR /&gt;h|'|i&lt;BR /&gt;|'|2023-12-12|'&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc print data=want noobs;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 14:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946685#M370726</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2024-10-08T14:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946688#M370727</link>
      <description>&lt;P&gt;Note that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;uses an "empty" INPUT with the "hold" modifier (@) to fill the _INFILE_ automatic variable; the actual INPUT has to come after the conversion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dsd dlm="|" truncover;
input @;
_infile_ = tranwrd(_infile_,"|'|",'|"''"|');
input
f1 :$10.
f2 :$10.
f3 :$10.
;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that, if those encrypted values need to stay as they were, you might have to deal with the consequences of the conversion later in your code.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 14:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946688#M370727</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-08T14:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946696#M370730</link>
      <description>&lt;P&gt;You need to first read in the next line by using an INPUT statement with a trailing&amp;nbsp;@.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if your input lines could have the ' in the first or last position on the line then your replacement code needs to be a little more clever.&amp;nbsp; Either figure out how to use regular expressions, or just prepend and append extra | to the line (which you can later remove).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines dsd dlm="|" truncover;
  input @ ;
  _infile_ = substr(tranwrd(cats('|',_infile_,'|'),"|'|",'|"''"|'),2);
  length f1-f4 $10;
  input f1-f4 ;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    f1    f2    f3            f4

 1     a     b     c
 2
 3           d     e
 4     '     f     g
 5     h     '     i
 6           '     2023-12-12    '
&lt;/PRE&gt;
&lt;P&gt;You might also want to test what happens if you have multiple of those values in a row.&amp;nbsp; This logic should make sure that they all get replaced.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input @ ;
  _infile_=cats('|',_infile_,'|');
  do while (index(_infile_,"|'|"));
    _infile_ = tranwrd(_infile_,"|'|",'|"''"|');
  end;
  _infile_=substr(_infile_,2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there is a limit of 32767 bytes for a character variable in SAS, including the _INFILE_ automatic variable used in this code.&amp;nbsp; So if the lines in the file are longer than that then you will need to find a different method to fix the file.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 15:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946696#M370730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-08T15:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946697#M370731</link>
      <description>&lt;P&gt;You need to first read in the next line by using an INPUT statement with a trailing&amp;nbsp;@.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if your input lines could have the ' in the first or last position on the line then your replacement code needs to be a little more clever.&amp;nbsp; Either figure out how to use regular expressions, or just prepend and append extra | to the line (which you can later remove).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines dsd dlm="|" truncover;
  input @ ;
  _infile_ = substr(tranwrd(cats('|',_infile_,'|'),"|'|",'|"''"|'),2);
  length f1-f4 $10;
  input f1-f4 ;
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    f1    f2    f3            f4

 1     a     b     c
 2
 3           d     e
 4     '     f     g
 5     h     '     i
 6           '     2023-12-12    '
&lt;/PRE&gt;
&lt;P&gt;You might also want to test what happens if you have multiple of those values in a row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input @ ;
  _infile_=cats('|',_infile_,'|');
  do while (index(_infile_,"|'|"));
    _infile_ = tranwrd(_infile_,"|'|",'|"''"|');
  end;
  _infile_=substr(_infile_,2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 15:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946697#M370731</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-08T15:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: single quote working similar to double quotes in dsd option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946752#M370742</link>
      <description>&lt;P&gt;As Tom said ,it was supposed to be when using option DSD.&lt;/P&gt;
&lt;P&gt;You need get rid of option DSD to avoid this behavior happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines ;
  input;
length f1-f4 $ 40;
f1=scan(_infile_,1,'|','m');
f2=scan(_infile_,2,'|','m');
f3=scan(_infile_,3,'|','m');
f4=scan(_infile_,4,'|','m');
datalines;
a|b|c
|||
|d|e
'|f|g
h|'|i
|'|2023-12-12|'
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2024 01:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/single-quote-working-similar-to-double-quotes-in-dsd-option/m-p/946752#M370742</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-09T01:52:36Z</dc:date>
    </item>
  </channel>
</rss>

