<?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: Creating a data from CSV file having delimited data in one cell in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622179#M183013</link>
    <description>&lt;P&gt;Thank you, Kurt.&lt;/P&gt;&lt;P&gt;Really appreciate your input.&lt;/P&gt;&lt;P&gt;The data has been loaded for product, accno and amount, while&amp;nbsp; leaving other columns blank.&lt;/P&gt;&lt;P&gt;The prroduct gold_insurance was populated in all the three rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 13:43:15 GMT</pubDate>
    <dc:creator>vickys</dc:creator>
    <dc:date>2020-02-04T13:43:15Z</dc:date>
    <item>
      <title>Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622163#M183006</link>
      <description>&lt;P&gt;Hi guru's Could some one help me to code one of our requirement. I tried my not iterative and have some challanne as I am new.&lt;/P&gt;&lt;P&gt;I have this data in CSV file below are the cell numbers i.e data in one column and three rows. There are some thousands of rows.&lt;/P&gt;&lt;P&gt;I have to remove that delimiter &amp;lt;tt&amp;gt; and load the data to corresponding fileds. Attaced is the input file but in notepad&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1ST CELL A1:A1&lt;/P&gt;&lt;P&gt;Name: abc&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: loan&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 123456&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 389.56&amp;lt;tt&amp;gt;&lt;BR /&gt;bonus: 3000&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: CCard_plat&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 5689&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 478.96&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: gold_insurance&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 1010102&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 103&amp;lt;tt&amp;gt;&lt;BR /&gt;bankcde: ICI&amp;lt;tt&amp;gt;&lt;BR /&gt;payment: 3094&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2nd CELL A1:B2&lt;/P&gt;&lt;P&gt;Name: vbsd&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: CCard_plat&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 74123&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 56.21&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: gold_insurance&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 2020201&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 189&amp;lt;tt&amp;gt;&lt;BR /&gt;bankcde: hdfc&amp;lt;tt&amp;gt;&lt;BR /&gt;payment: 605&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;3rd CELL A1:B3&lt;/P&gt;&lt;P&gt;Name: klhj&amp;lt;tt&amp;gt;&lt;BR /&gt;Product: gold_insurance&amp;lt;tt&amp;gt;&lt;BR /&gt;accno: 3030312&amp;lt;tt&amp;gt;&lt;BR /&gt;amount: 563&amp;lt;tt&amp;gt;&lt;BR /&gt;bankcde: kk&amp;lt;tt&amp;gt;&lt;BR /&gt;payment: 489&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am expecting the output of the data as below: Where there is no data for any of the product then it should load with blank and fill the remaining fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name Product Accno Amount Bonus Card_type CC_Accno CC_Amount_no Insurance_Type Insurance_No Insurance_Amt Bank_Cde Payment&lt;BR /&gt;abc&amp;nbsp; &amp;nbsp; &amp;nbsp; loan&amp;nbsp; &amp;nbsp; 123456&amp;nbsp; &amp;nbsp; &amp;nbsp;389.56&amp;nbsp; &amp;nbsp; &amp;nbsp; 3000&amp;nbsp; &amp;nbsp; &amp;nbsp;ccard_plat&amp;nbsp; &amp;nbsp; &amp;nbsp;5689&amp;nbsp; &amp;nbsp; &amp;nbsp; 478.96&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gold_insurance&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1010102&amp;nbsp; &amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; ICI&amp;nbsp; &amp;nbsp; &amp;nbsp; 3094&lt;BR /&gt;vbsd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ccard_plat&amp;nbsp; &amp;nbsp; &amp;nbsp;74123&amp;nbsp; &amp;nbsp; &amp;nbsp; 56.21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gold_insurance&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2020201&amp;nbsp; &amp;nbsp; &amp;nbsp;189&amp;nbsp; &amp;nbsp; &amp;nbsp;hdfc&amp;nbsp; &amp;nbsp; &amp;nbsp;605&lt;BR /&gt;klhj&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gold_insurance&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3030312&amp;nbsp; &amp;nbsp; &amp;nbsp;563&amp;nbsp; &amp;nbsp; &amp;nbsp;kk&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 489&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate your inputs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 11:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622163#M183006</guid>
      <dc:creator>vickys</dc:creator>
      <dc:date>2020-02-04T11:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622172#M183011</link>
      <description>&lt;P&gt;See:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length
  Name $10
  Product $20
  Accno $6
;
retain
  Name Product Accno Amount Bonus Card_type CC_Accno CC_Amount_no
  Insurance_Type Insurance_No Insurance_Amt Bank_Cde Payment
;
infile datalines eof=done;
input;
select (scan(_infile_,1,':'));
  when ('Name') do;
    if name ne ''
    then do;
      output;
      call missing(
        Name,Product,Accno,Amount,Bonus,Card_type,CC_Accno,CC_Amount_no,
        Insurance_Type,Insurance_No,Insurance_Amt,Bank_Cde,Payment
      );
    end;
    name = scan(scan(_infile_,2,':'),1,'&amp;lt;');
  end;
  when ('Product') product = scan(scan(_infile_,2,':'),1,'&amp;lt;');
  when ('accno') accno = scan(scan(_infile_,2,':'),1,'&amp;lt;');
  when ('amount') amount = input(scan(scan(_infile_,2,':'),1,'&amp;lt;'),best.);
  otherwise;
end;
goto dsend;
done: output;
dsend:
datalines;
1ST CELL A1:A1

Name: abc&amp;lt;tt&amp;gt;
Product: loan&amp;lt;tt&amp;gt;
accno: 123456&amp;lt;tt&amp;gt;
amount: 389.56&amp;lt;tt&amp;gt;
bonus: 3000&amp;lt;tt&amp;gt;
Product: CCard_plat&amp;lt;tt&amp;gt;
accno: 5689&amp;lt;tt&amp;gt;
amount: 478.96&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 1010102&amp;lt;tt&amp;gt;
amount: 103&amp;lt;tt&amp;gt;
bankcde: ICI&amp;lt;tt&amp;gt;
payment: 3094

 

2nd CELL A1:B2

Name: vbsd&amp;lt;tt&amp;gt;
Product: CCard_plat&amp;lt;tt&amp;gt;
accno: 74123&amp;lt;tt&amp;gt;
amount: 56.21&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 2020201&amp;lt;tt&amp;gt;
amount: 189&amp;lt;tt&amp;gt;
bankcde: hdfc&amp;lt;tt&amp;gt;
payment: 605


3rd CELL A1:B3

Name: klhj&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 3030312&amp;lt;tt&amp;gt;
amount: 563&amp;lt;tt&amp;gt;
bankcde: kk&amp;lt;tt&amp;gt;
payment: 489
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 12:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622172#M183011</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T12:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622179#M183013</link>
      <description>&lt;P&gt;Thank you, Kurt.&lt;/P&gt;&lt;P&gt;Really appreciate your input.&lt;/P&gt;&lt;P&gt;The data has been loaded for product, accno and amount, while&amp;nbsp; leaving other columns blank.&lt;/P&gt;&lt;P&gt;The prroduct gold_insurance was populated in all the three rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 13:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622179#M183013</guid>
      <dc:creator>vickys</dc:creator>
      <dc:date>2020-02-04T13:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622188#M183015</link>
      <description>&lt;P&gt;The code is just a proof of concept, and incomplete at that.&lt;/P&gt;
&lt;P&gt;This now deals correctly with all data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain
  Name pr Product Accno Amount Bonus Card_type CC_Accno CC_Amount_no
  Insurance_Type Insurance_No Insurance_Amt Bank_Cde Payment
;
length
  Name $10
  pr Product Card_type Insurance_Type $20
  Accno CC_Accno Insurance_No $6
  Bank_Cde $10
;
infile datalines eof=done;
input;
select (scan(_infile_,1,':'));
  when ('Name') do;
    if name ne ''
    then do;
      output;
      call missing(
        Name,pr,Product,Accno,Amount,Bonus,Card_type,CC_Accno,CC_Amount_no,
        Insurance_Type,Insurance_No,Insurance_Amt,Bank_Cde,Payment
      );
    end;
    name = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
  end;
  when ('Product') do;
    pr = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
    select (pr);
      when ('loan') product = pr;
      when ('CCard_plat') card_type = pr;
      when ('gold_insurance') insurance_type = pr;
    end;
  end;
  when ('accno') select (pr);
    when ('loan') accno = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
    when ('CCard_plat') CC_Accno = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
    when ('gold_insurance') Insurance_No = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
  end;
  when ('amount') select (pr);
    when ('loan') amount = input(scan(scan(_infile_,2,':'),1,'&amp;lt;'),best.);
    when ('CCard_plat') CC_Amount_no = input(scan(scan(_infile_,2,':'),1,'&amp;lt;'),best.);
    when ('gold_insurance') Insurance_Amt = input(scan(scan(_infile_,2,':'),1,'&amp;lt;'),best.);
  end;
  when ('bonus') bonus = input(scan(scan(_infile_,2,':'),1,'&amp;lt;'),best.);
  when ('bankcde') Bank_Cde = strip(scan(scan(_infile_,2,':'),1,'&amp;lt;'));
  when ('payment') Payment = input(scan(_infile_,2,':'),best.);
  otherwise;
end;
goto dsend;
done: output;
dsend:
drop pr;
datalines;
1ST CELL A1:A1

Name: abc&amp;lt;tt&amp;gt;
Product: loan&amp;lt;tt&amp;gt;
accno: 123456&amp;lt;tt&amp;gt;
amount: 389.56&amp;lt;tt&amp;gt;
bonus: 3000&amp;lt;tt&amp;gt;
Product: CCard_plat&amp;lt;tt&amp;gt;
accno: 5689&amp;lt;tt&amp;gt;
amount: 478.96&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 1010102&amp;lt;tt&amp;gt;
amount: 103&amp;lt;tt&amp;gt;
bankcde: ICI&amp;lt;tt&amp;gt;
payment: 3094

 

2nd CELL A1:B2

Name: vbsd&amp;lt;tt&amp;gt;
Product: CCard_plat&amp;lt;tt&amp;gt;
accno: 74123&amp;lt;tt&amp;gt;
amount: 56.21&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 2020201&amp;lt;tt&amp;gt;
amount: 189&amp;lt;tt&amp;gt;
bankcde: hdfc&amp;lt;tt&amp;gt;
payment: 605


3rd CELL A1:B3

Name: klhj&amp;lt;tt&amp;gt;
Product: gold_insurance&amp;lt;tt&amp;gt;
accno: 3030312&amp;lt;tt&amp;gt;
amount: 563&amp;lt;tt&amp;gt;
bankcde: kk&amp;lt;tt&amp;gt;
payment: 489
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 14:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622188#M183015</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T14:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622197#M183019</link>
      <description>&lt;P&gt;I think your attempt to describe the CSV file is adding confusion to your request.&amp;nbsp; Can't you just paste a couple of lines from the CSV into your question?&amp;nbsp; Use the Insert Code button (looks like {i} on the menu) to get a pop-up window to paste the text.&amp;nbsp; Make sure to open the CSV file with a text editor and not with Excel so that you can see the actual content and not have Excel mangle it into a spreadsheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have three columns in the CSV file?&amp;nbsp; And each one have these name-value pairs?&amp;nbsp; Is there any significance to the pair being in the 2nd column instead of the 1st or 3rd column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is probably going to be easiest to read it into a tall structure.&amp;nbsp; Perhaps something like:&lt;/P&gt;
&lt;PRE&gt;ROW|COL|ORD|NAME|VALUE
1|1|1|Name|abc
1|1|2|Product|loan
...
1|2|1|Name|vbsd
1|2|2|Product|CCard_plat
...&lt;/PRE&gt;
&lt;P&gt;So assuming each row has only three columns your code might look something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length row col ord 8 name value $200 ;
  infile 'myfile.csv' dsd truncover ;
  length cell pair $32767 ;
  row+1;
  do cell=1 to 3 ;
    input cell @;
    cell = tranwrd(cell,'&amp;lt;tt&amp;gt;','FF'x);
    do ord=1 to countw(cell,'FF'x);
      pair=scan(cell,ord,'FF'x);
      name=scan(pair,1,':');
      value =left(scan(pair,2,':'));
      output;
    end;
  end;
  drop cell pair;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you could use PROC TRANSPOSE with to create a wide dataset.&amp;nbsp; To use the value of NAME as the name of the variable to create use the ID statement in the PROC TRANSPOSE step.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 15:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622197#M183019</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T15:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data from CSV file having delimited data in one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622906#M183266</link>
      <description>&lt;P&gt;Many Thanks, Kurt.&lt;/P&gt;&lt;P&gt;Though I posted my requirement&amp;nbsp; slight bit different, but it was 95% same.&lt;/P&gt;&lt;P&gt;Really appreciate your inputs&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 23:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-data-from-CSV-file-having-delimited-data-in-one-cell/m-p/622906#M183266</guid>
      <dc:creator>vickys</dc:creator>
      <dc:date>2020-02-06T23:58:04Z</dc:date>
    </item>
  </channel>
</rss>

