<?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: How to read records using column pointer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646971#M193579</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Very ugly data buy try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd dlm="0ad0"x firstobs=2;
  input text : $ 1024.;
  text = tranwrd(text,",,",",0,");
    i=1;
    var = scan(text,i,",");
    do while(var ne "");
      output;
      i+1;
      var = scan(text,i,",");
    end;
  keep var;
cards;
student_id,mark1,mark2,mark3
1A,58,52,
85,2B,78,
43,,1C,58,98,65,4A,
87,99,95,5D,45,,43,6S,
23,
45,,7F,32,56,45,
1D,
32,45,67,2C,45,67,33,6G,43
37,87
;
run;

data want;
  length student_id $ 10;
  array M[2:4] mark1 mark2 mark3;
  do _N_=1 to 4;
    set have;
    if _N_ = 1 then student_id = var;
               else
                do;
                  M[_N_] = input(var, ??best32.);
                end;
  end;
  drop var;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;All the best&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 06:50:42 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-05-12T06:50:42Z</dc:date>
    <item>
      <title>How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646962#M193574</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I want to read following records using column pointer and create dataset. Please help me.&lt;/P&gt;&lt;P&gt;file:&lt;/P&gt;&lt;P&gt;student_id,mark1,mark2,mark3&lt;BR /&gt;1A,58,52,&lt;BR /&gt;85,2B,78,&lt;BR /&gt;43,,1C,58,98,65,4A,&lt;BR /&gt;87,99,95,5D,45,,43,6S,&lt;BR /&gt;23,&lt;BR /&gt;45,,7F,32,56,45,&lt;BR /&gt;1D,&lt;BR /&gt;32,45,67,2C,45,67,33,6G,43&lt;BR /&gt;37,87&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Required Output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;student_id&lt;/TD&gt;&lt;TD&gt;mark1&lt;/TD&gt;&lt;TD&gt;mark2&lt;/TD&gt;&lt;TD&gt;mark3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1A&lt;/TD&gt;&lt;TD&gt;58&lt;/TD&gt;&lt;TD&gt;52&lt;/TD&gt;&lt;TD&gt;85&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2B&lt;/TD&gt;&lt;TD&gt;78&lt;/TD&gt;&lt;TD&gt;43&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1C&lt;/TD&gt;&lt;TD&gt;58&lt;/TD&gt;&lt;TD&gt;98&lt;/TD&gt;&lt;TD&gt;65&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4A&lt;/TD&gt;&lt;TD&gt;87&lt;/TD&gt;&lt;TD&gt;99&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5D&lt;/TD&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;43&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6S&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;and so on.... for missing marks put 0.&lt;/P&gt;&lt;P&gt;please help to solve&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 05:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646962#M193574</guid>
      <dc:creator>Navnath_Gajare</dc:creator>
      <dc:date>2020-05-12T05:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646967#M193576</link>
      <description>&lt;P&gt;1. This look like badly imported data. Import it correctly rather than try to fix the mess.&lt;/P&gt;
&lt;P&gt;2. Your example makes no sense as you have 4 variables and some lines have more than 4 values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 05:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646967#M193576</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-12T05:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646971#M193579</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Very ugly data buy try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd dlm="0ad0"x firstobs=2;
  input text : $ 1024.;
  text = tranwrd(text,",,",",0,");
    i=1;
    var = scan(text,i,",");
    do while(var ne "");
      output;
      i+1;
      var = scan(text,i,",");
    end;
  keep var;
cards;
student_id,mark1,mark2,mark3
1A,58,52,
85,2B,78,
43,,1C,58,98,65,4A,
87,99,95,5D,45,,43,6S,
23,
45,,7F,32,56,45,
1D,
32,45,67,2C,45,67,33,6G,43
37,87
;
run;

data want;
  length student_id $ 10;
  array M[2:4] mark1 mark2 mark3;
  do _N_=1 to 4;
    set have;
    if _N_ = 1 then student_id = var;
               else
                do;
                  M[_N_] = input(var, ??best32.);
                end;
  end;
  drop var;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;All the best&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 06:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646971#M193579</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-12T06:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646972#M193580</link>
      <description>On the INFILE statement, be sure to use the DSD option.  Then:&lt;BR /&gt;&lt;BR /&gt;input student_id $ mark1 mark2 mark3 @@ ;&lt;BR /&gt;&lt;BR /&gt;If the file actually contains the variable names on the first line  also add the option FIRSTOBS=2 to the INFILE statement.</description>
      <pubDate>Tue, 12 May 2020 06:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646972#M193580</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-05-12T06:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646982#M193586</link>
      <description>I think that DSD isn't any help here. With DSD you will handle double comma (`,,`) but at the same time that comma which sometime is at the end of lines will mess the data. &lt;BR /&gt;&lt;BR /&gt;Bart</description>
      <pubDate>Tue, 12 May 2020 07:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/646982#M193586</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-12T07:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647071#M193614</link>
      <description>&lt;P&gt;It looks like uneasy.&lt;/P&gt;
&lt;P&gt;the last two obs, Do you miss a comma ',' ?&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;32,45,67,2C,45,67,33,6G,43&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;37,87&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;--&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;32,45,67,2C,45,67,33,6G,43&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;37,87&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename have temp;
data _null_;
input;
file have;
put _infile_;
cards;
student_id,mark1,mark2,mark3
1A,58,52,
85,2B,78,
43,,1C,58,98,65,4A,
87,99,95,5D,45,,43,6S,
23,
45,,7F,32,56,45,
1D,
32,45,67,2C,45,67,33,6G,43,
37,87
;






filename have2 temp;
data _null_;
 infile have;
 input;
 file have2;
 if _n_&amp;gt;1 then put _infile_;
run;
data want;
infile have2 dsd recfm=n ;
input (student_id mark1-mark3) ($);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 May 2020 12:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647071#M193614</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-12T12:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647075#M193615</link>
      <description>&lt;P&gt;I saved this text:&lt;/P&gt;
&lt;PRE&gt;1A,58,52,
85,2B,78,
43,,1C,58,98,65,4A,
87,99,95,5D,45,,43,6S,
23,
45,,7F,32,56,45,
1D,
32,45,67,2C,45,67,33,6G,43,
37,87&lt;/PRE&gt;
&lt;P&gt;(note the comma at the end of the next-to-last line, this is missing from your text and would comlicate things quite a lot)&lt;/P&gt;
&lt;P&gt;to a text file and ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile '/folders/myfolders/messy.txt' end=done;
length line $100 student $2;
retain line;
do while (countw(line,',','m') &amp;lt;= 4 and not done);
  input;
  line = cats(line,_infile_);
end;
do while (countw(line,',','m') &amp;gt;= 4);
  student = scan(line,1,',','m');
  score1 = input(scan(line,2,',','m'),best.);
  score2 = input(scan(line,3,',','m'),best.);
  score3 = input(scan(line,4,',','m'),best.);
  call scan(line,4,pos,len,',','m');
  if pos + len le lengthc(line)
  then line = substr(line,pos+len+1);
  else line = "";
  output;
end;
if done then stop;
keep student score:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;resulting in this dataset:&lt;/P&gt;
&lt;PRE&gt;1	1A	58	52	85	
2	2B	78	43	.	
3	1C	58	98	65	
4	4A	87	99	95	
5	5D	45	.	43	
6	6S	23	45	.	
7	7F	32	56	45	
8	1D	32	45	67	
9	2C	45	67	33	
10	6G	43	37	87	
&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 May 2020 12:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647075#M193615</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-12T12:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647100#M193623</link>
      <description>&lt;P&gt;Since this data looks extremely familiar, have you determined where the extra line feeds came from yet?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column (and row) pointer inputs is used when you &lt;STRONG&gt;know&lt;/STRONG&gt; ahead of time which column and/or row a value will appear.&lt;/P&gt;
&lt;P&gt;This does not appear to be the case with this data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this were my project I would trace the history of the file back to the idiot that managed to insert a whole bunch of linefeed/carriage control (which ever) characters and beat them severely with wet noodles. Then try to find a version without the irregular line behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: train people very carefully when doing data entry not to randomly use the Enter, Tab or other keys.&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 14:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647100#M193623</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-12T14:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to read records using column pointer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647122#M193630</link>
      <description>&lt;P&gt;Looking back, I see that you posted the exact same question in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Read-nonstandard-csv-files/m-p/645923" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Read-nonstandard-csv-files/m-p/645923&lt;/A&gt;&amp;nbsp;and accepted a solution there.&lt;/P&gt;
&lt;P&gt;What did not work out with that solution, so that you posted this again, or were you just a little bored?&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 15:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-records-using-column-pointer/m-p/647122#M193630</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-12T15:09:08Z</dc:date>
    </item>
  </channel>
</rss>

