<?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: Need help to get desired output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-get-desired-output/m-p/963536#M375361</link>
    <description>&lt;P&gt;By INPUT I assume you mean some TEXT file that you are reading.&amp;nbsp; Since it looks like a delimited text just use the DSD option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for that to work you need to have a REAL delimited file.&amp;nbsp; And it looks to me like there is one more field in the second line than in the other lines.&amp;nbsp; That is because field values that contain the delimiter (comma in this case) need to be quoted.&amp;nbsp; For the second line to have 5 values like the others it should look like this:&lt;/P&gt;
&lt;PRE&gt;XYZ,DATA,"G:\Data\XYZ\DATA\Test2.txt---bkp,sfsfsf---",12345,01/01/2025 14:17:14
&lt;/PRE&gt;
&lt;P&gt;You should find the process that made that file and fix it so that values with delimiters are quoted.&amp;nbsp; For example if you made the file with SAS make sure to use the DSD option of the FILE statement in the data step that wrote the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are stuck trying to deal with the invalidly formatted file and only one field can possible have unquoted delimiters then you can get it work by using SCAN() to read from the _INFILE_ automatic variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test first let's convert your example into an actual file we can code with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option parmcards=csv;
filename csv temp;
parcards4;
XYZ,DATA,G:\Data\XYZ\DATA\Test1.txt,1234,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test2.txt---bkp,sfsfsf---,12345,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test3.txt@#ttabd--.txt,123456,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test4.txt,1234777,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test5.txt,123479878,01/01/2025 14:17:14
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can use the fileref CSV to point to that example file.&lt;/P&gt;
&lt;P&gt;We can read the first two fields using normal INPUT.&amp;nbsp; Then use SCAN() to extract the other field you wanted by scanning from the right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover;
  length var1 $3 var2 $4 var3 $12 ;
  input var1 var2 ;
  var3 = scan(_infile_,-2,',','mq');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1743896109689.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105959i293C43D6A4836EF6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1743896109689.png" alt="Tom_0-1743896109689.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Apr 2025 23:42:06 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-04-05T23:42:06Z</dc:date>
    <item>
      <title>Need help to get desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-get-desired-output/m-p/963534#M375360</link>
      <description>&lt;P&gt;I have below sample data and need output as mentioned.&lt;/P&gt;
&lt;P&gt;Can you please suggest.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Input&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;XYZ,DATA,&lt;STRONG&gt;G:\Data\XYZ\DATA\Test1.txt&lt;/STRONG&gt;,1234,01/01/2025 14:17:14&lt;/P&gt;
&lt;P&gt;XYZ,DATA,&lt;STRONG&gt;G:\Data\XYZ\DATA\Test2.txt---bkp,sfsfsf---&lt;/STRONG&gt;,12345,01/01/2025 14:17:14&lt;/P&gt;
&lt;P&gt;XYZ,DATA,&lt;STRONG&gt;G:\Data\XYZ\DATA\Test3.txt@#ttabd--.txt&lt;/STRONG&gt;,123456,01/01/2025 14:17:14&lt;/P&gt;
&lt;P&gt;XYZ,DATA,&lt;STRONG&gt;G:\Data\XYZ\DATA\Test4.txt&lt;/STRONG&gt;,1234777,01/01/2025 14:17:14&lt;/P&gt;
&lt;P&gt;XYZ,DATA,&lt;STRONG&gt;G:\Data\XYZ\DATA\Test5.txt&lt;/STRONG&gt;,123479878,01/01/2025 14:17:14&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;XYZ,DATA,1234&lt;/P&gt;
&lt;P&gt;XYZ,DATA,12345&lt;/P&gt;
&lt;P&gt;XYZ,DATA,123456&lt;/P&gt;
&lt;P&gt;XYZ,DATA,1234777&lt;/P&gt;
&lt;P&gt;XYZ,DATA,123479878&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Note : 3rd column is path and file name but file name is having different extra character like ,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111267"&gt;@--&lt;/a&gt; etc, so I am getting blank and output is coming correctly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 20:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-get-desired-output/m-p/963534#M375360</guid>
      <dc:creator>kumarsandip975</dc:creator>
      <dc:date>2025-04-05T20:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to get desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-get-desired-output/m-p/963536#M375361</link>
      <description>&lt;P&gt;By INPUT I assume you mean some TEXT file that you are reading.&amp;nbsp; Since it looks like a delimited text just use the DSD option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for that to work you need to have a REAL delimited file.&amp;nbsp; And it looks to me like there is one more field in the second line than in the other lines.&amp;nbsp; That is because field values that contain the delimiter (comma in this case) need to be quoted.&amp;nbsp; For the second line to have 5 values like the others it should look like this:&lt;/P&gt;
&lt;PRE&gt;XYZ,DATA,"G:\Data\XYZ\DATA\Test2.txt---bkp,sfsfsf---",12345,01/01/2025 14:17:14
&lt;/PRE&gt;
&lt;P&gt;You should find the process that made that file and fix it so that values with delimiters are quoted.&amp;nbsp; For example if you made the file with SAS make sure to use the DSD option of the FILE statement in the data step that wrote the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are stuck trying to deal with the invalidly formatted file and only one field can possible have unquoted delimiters then you can get it work by using SCAN() to read from the _INFILE_ automatic variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test first let's convert your example into an actual file we can code with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option parmcards=csv;
filename csv temp;
parcards4;
XYZ,DATA,G:\Data\XYZ\DATA\Test1.txt,1234,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test2.txt---bkp,sfsfsf---,12345,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test3.txt@#ttabd--.txt,123456,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test4.txt,1234777,01/01/2025 14:17:14
XYZ,DATA,G:\Data\XYZ\DATA\Test5.txt,123479878,01/01/2025 14:17:14
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can use the fileref CSV to point to that example file.&lt;/P&gt;
&lt;P&gt;We can read the first two fields using normal INPUT.&amp;nbsp; Then use SCAN() to extract the other field you wanted by scanning from the right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover;
  length var1 $3 var2 $4 var3 $12 ;
  input var1 var2 ;
  var3 = scan(_infile_,-2,',','mq');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1743896109689.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105959i293C43D6A4836EF6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1743896109689.png" alt="Tom_0-1743896109689.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 23:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-get-desired-output/m-p/963536#M375361</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-05T23:42:06Z</dc:date>
    </item>
  </channel>
</rss>

