<?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 Complex delimiting in SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608544#M17698</link>
    <description>&lt;P&gt;Hey community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some data with a total of 52 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue is that these variables when exported from the data capture database they are lumped together all in one excel cell, with different combinations of the variables. For example&amp;nbsp;(made up data has been used for example purposes).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Excel cell A1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; site_id = '0', pt_initials = 'AA', dob = '1800-01-01', sex = '1', form_3_followup_complete = '0', study_id = '000'&lt;/P&gt;&lt;P&gt;Excel cell B1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fup_cont_attemp = '1', fup_time = '30', fup_yesno = '0', fup_nocall = '2', fup_date = '1900-01-01 13:30', fup_comment = 'weather is nice today'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I code in SAS so that it presents it like the below?&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;site_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;pt_initials&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;dob&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P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TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;30&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1900-01-01 13:30&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Weather is nice today&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 01 Dec 2019 07:07:13 GMT</pubDate>
    <dc:creator>Luke01</dc:creator>
    <dc:date>2019-12-01T07:07:13Z</dc:date>
    <item>
      <title>Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608544#M17698</link>
      <description>&lt;P&gt;Hey community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some data with a total of 52 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue is that these variables when exported from the data capture database they are lumped together all in one excel cell, with different combinations of the variables. For example&amp;nbsp;(made up data has been used for example purposes).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Excel cell A1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; site_id = '0', pt_initials = 'AA', dob = '1800-01-01', sex = '1', form_3_followup_complete = '0', study_id = '000'&lt;/P&gt;&lt;P&gt;Excel cell B1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fup_cont_attemp = '1', fup_time = '30', fup_yesno = '0', fup_nocall = '2', fup_date = '1900-01-01 13:30', fup_comment = 'weather is nice today'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I code in SAS so that it presents it like the below?&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;site_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;pt_initials&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;dob&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;sex&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;form_3_followup_complete&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;study_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_cont_attemp&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_time&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_yesno&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_nocall&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_date&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fup_comment&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;AA&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1800-01-01&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&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 07:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608544#M17698</guid>
      <dc:creator>Luke01</dc:creator>
      <dc:date>2019-12-01T07:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608549#M17699</link>
      <description>&lt;P&gt;Export from the database to a file format that is easier to read, e.g. csv. In fact your text data already seems to be comma delimited.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 08:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608549#M17699</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-01T08:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608552#M17701</link>
      <description>&lt;P&gt;yes it is cvs, the issue being i have been given the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue being is that if you delimit it via comma, then you get each variable + the value in the same cell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have the variable name as the column title and the value below such as in the example.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 08:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608552#M17701</guid>
      <dc:creator>Luke01</dc:creator>
      <dc:date>2019-12-01T08:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608557#M17702</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301821"&gt;@Luke01&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;My first reaction is to tell you to go back to the data provider and ask for data in a more common structure for data exchange (like a proper .csv or an XML).&lt;/P&gt;
&lt;P&gt;But let's assume you have to deal with what you've got. If this is a text file in the structure as you describe then below code should do the job. I haven't added all the variables but the code demonstrates the approach and that it's working.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create temporary file with .csv data structure */
filename havecsv temp lrecl=400;
data _null_;
  file havecsv;
  length str $400;
  str="site_id = '0', pt_initials = 'AA', dob = '1800-01-01', sex = '1', form_3_followup_complete = '0', study_id = '000'";
  str=cats('"',str,'","',"fup_cont_attemp = '1', fup_time = '30', fup_yesno = '0', fup_nocall = '2', fup_date = '1900-01-01 13:30', fup_comment = 'weather is nice today'",'"');
  put str;
  stop;
run;

/* read .csv structured data */
/*filename havecsv '&amp;lt;path to your .csv&amp;gt;' lrecl=400;*/
data want;
  attrib
    site_id     informat=$10.
    pt_initials informat=$10.
    dob         informat=yymmdd10.  format=date9.
    sex         informat=$1.
    fup_date    informat=ymddttm24. format=datetime20.
    ;
  infile havecsv truncover scanover dlm=',' dsd;
  input 
    @'site_id =' site_id
    @'pt_initials =' pt_initials
    @'dob =' dob
    @'sex =' sex
    @'fup_date =' fup_date
    ;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 352px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34352iA56A6EF85D91F975/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code will read all the source data belonging to the same line into a single observation meaning your "cell A" and "cell B" will be read into a single SAS observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's not how you show us the desired result but given your source data that's how it looks like to me you should be doing it. This assumes that there is never the same variable name "the same key value" on a single line (like same "variable" in different cells on the same row).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 09:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608557#M17702</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-01T09:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608558#M17703</link>
      <description>&lt;P&gt;thank you, i am new to SAS to this will also give me an opportunity to research all the code terms you have provided. I will reply with how i go &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 09:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608558#M17703</guid>
      <dc:creator>Luke01</dc:creator>
      <dc:date>2019-12-01T09:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608560#M17704</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301821"&gt;@Luke01&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The important keywords to look-up stuff in the documentation are SCANOVER in combination with DSD.&lt;/P&gt;
&lt;P&gt;Reading data in the structure you have is not very common and documentation might be a bit "spread out" - but it's all there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCANOVER allows to parse an input buffer for strings (using these strings as "delimiter") and then read the value following the string.&lt;/P&gt;
&lt;P&gt;DSD used together with SCANOVER then allows to read the value within the quotes (with the quotes excluded from the value read).&lt;/P&gt;
&lt;P&gt;The INFORMAT instructs SAS how to read the text value from source into a SAS variable. The FORMAT instructs SAS how to present (print) the value stored in a SAS variable.&lt;/P&gt;
&lt;P&gt;Defining SAS variables using an ATTRIB statement will implicitly create SAS numeric or character variables based on the Informat and format used. It will also implicitly assign the Lengths to the variables based on the Informat/Format definitions. You can use the LENGTH option of the ATTRIB statement to explicitly define the type (character or numeric) and length of a variable.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 09:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608560#M17704</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-01T09:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Complex delimiting in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608588#M17706</link>
      <description>&lt;P&gt;Please post an example as TEXT (either attach as a .txt file or paste into the Insert Code pop-up window).&amp;nbsp; It sounds like you are saying you have CSV file with one line and two columns that looks like:&lt;/P&gt;
&lt;PRE&gt;"site_id = '0', pt_initials = 'AA', dob = '1800-01-01', sex = '1', form_3_followup_complete = '0', study_id = '000'","fup_cont_attemp = '1', fup_time = '30', fup_yesno = '0', fup_nocall = '2', fup_date = '1900-01-01 13:30', fup_comment = 'weather is nice today'"&lt;/PRE&gt;
&lt;P&gt;You could convert that into a file that just has the comma separated NAME=VALUE pairs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   infile 'original.csv' dsd truncover ;
   file 'step1.csv' ;
   length cell $32767. ;
   do until (cell=' ');
     input cell :$32767.  @;
     put cell ',' @;
   end;
   put +(-1) ' ' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;site_id = '0', pt_initials = 'AA', dob = '1800-01-01', sex = '1', form_3_followup_complete = '0', study_id = '000',fup_cont_attemp = '1', fup_time = '30', fup_yesno = '0', fup_nocall = '2', fup_date = '1900-01-01 13:30', fup_comment = 'weather is nice today'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could read in the name=value pairs and then parse them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall ;
  infile 'step1.csv' dsd truncover ;
  length row order 8 name $32 value $200 cell $300;
  row+1;
  do order=1 by 1 until (cell=' ');
     input cell @;
     if cell=' ' then continue;
     name=scan(cell,1,'=');
     value=scan(cell,2,'=');
     output;
  end;
  input;
  drop cell;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use PROC TRANSPOSE to convert this tall structure into a wide one. But make sure you don't have the same NAME value appearing more than once in the same row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=tall out=want ;
  by row;
  id name ;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also add logic at some point to convert some of the values into numeric, probably based on the name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2019 17:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Complex-delimiting-in-SAS/m-p/608588#M17706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-01T17:26:20Z</dc:date>
    </item>
  </channel>
</rss>

