<?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: Character variables to columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532029#M145741</link>
    <description>&lt;P&gt;So what does the SAS data set look like made from that Excel data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 15:08:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-02-01T15:08:37Z</dc:date>
    <item>
      <title>Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532013#M145735</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-standard"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-left"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-left"&gt;&lt;DIV class="lia-message-subject"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an excel file that has data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Services&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BC-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BC-1&lt;BR /&gt;MI-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BC-1&lt;BR /&gt;PC-1&lt;BR /&gt;MI-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Assess B-1&lt;BR /&gt;BC-1&lt;BR /&gt;HR-1&lt;BR /&gt;MHA-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CC-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Assess B-1&lt;BR /&gt;BC-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HR-4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BN-1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to do is transpose each category into&amp;nbsp; a column from&amp;nbsp; each cell. So what I would like is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BC&lt;/TD&gt;&lt;TD&gt;MI&lt;/TD&gt;&lt;TD&gt;PC&lt;/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t;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated thank you!&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532013#M145735</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2019-02-01T14:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532029#M145741</link>
      <description>&lt;P&gt;So what does the SAS data set look like made from that Excel data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532029#M145741</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-01T15:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532030#M145742</link>
      <description>&lt;P&gt;Import the excel file using PROC IMPORT, then you can write a data step to parse your data using some functions in sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import 
  datafile="/user/kiran/Services.xlsx" 
  dbms=xlsx
  out=work.have 
  replace;
run;

/* For my test, I have the datastep instead of import */
data have;
infile datalines truncover;
input Services $100.;
datalines;
BC-1
0
0
BC-1 MI-1
0
BC-1 PC-1 MI-1
Assess B-1 BC-1 HR-1 MHA-1
CC-1
Assess B-1 BC-1
HR-4
BN-1
;
run;

data want;
set have;
BC=ifc(find(Services,'BC-')&amp;gt;0,substr(Services,find(Services,'BC-')+3,1),'0');
MI=ifc(find(Services,'MI-')&amp;gt;0,substr(Services,find(Services,'MI-')+3,1),'0');
PC=ifc(find(Services,'PC-')&amp;gt;0,substr(Services,find(Services,'PC-')+3,1),'0');
AssessB=ifc(find(Services,'Assess B-')&amp;gt;0,substr(Services,find(Services,'Assess B-')+9,1),'0');
HR=ifc(find(Services,'HR-')&amp;gt;0,substr(Services,find(Services,'HR-')+3,1),'0');
BN=ifc(find(Services,'BN-')&amp;gt;0,substr(Services,find(Services,'BN-')+3,1),'0');
MHA=ifc(find(Services,'MHA-')&amp;gt;0,substr(Services,find(Services,'MHA-')+4,1),'0');
CC=ifc(find(Services,'CC-')&amp;gt;0,substr(Services,find(Services,'CC-')+3,1),'0');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532030#M145742</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-02-01T15:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532075#M145760</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I imported the excel file - SAS only took the first few characters, cutting off all the data underneath.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So data that is in Excel like this:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OP - 1&lt;BR /&gt;ALC - 1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Became this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OP-1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in as SAS Data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thoughts?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 16:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532075#M145760</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2019-02-01T16:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532093#M145761</link>
      <description>&lt;P&gt;Are you saying that in Excel the single cells displays as multiple lines?&amp;nbsp; If so it probably has a LineFeed character embedded in the string.&lt;/P&gt;
&lt;P&gt;You can use the $HEX format to display some of the values in your SAS dataset to see what character is inserted between the two values.&amp;nbsp; '0A'x is a linefeed and '0D'x is a carriage return.&amp;nbsp; &amp;nbsp;If you try to print those without using the $HEX format then they will cause the location to move to the beginning of the line (carriage return) or jump down one row (line feed) which can make a print out look very confusing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have an XLS (old format) or XLSX (new format) file?&amp;nbsp; Or some other format.&lt;/P&gt;
&lt;P&gt;What method did you use to convert it to a SAS dataset?&amp;nbsp; PROC IMPORT?&amp;nbsp; If so what DBMS setting did you use? XLSX? EXCEL? Let SAS guess based on the file extension?&lt;/P&gt;
&lt;P&gt;If you used XLSX engine then it should make the variable long enough for the longest string in the column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 16:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532093#M145761</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-01T16:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables to columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532142#M145778</link>
      <description>Hi Tom, You're spot on! it imported on a seperate line in SAS as well. It was just hidden when I glanced at the dataset.&lt;BR /&gt;&lt;BR /&gt;Is there a way I can parse out the data by lines?</description>
      <pubDate>Fri, 01 Feb 2019 18:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-to-columns/m-p/532142#M145778</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2019-02-01T18:22:40Z</dc:date>
    </item>
  </channel>
</rss>

