<?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: Converting free text variable into numeric while expanding to long dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971118#M43386</link>
    <description>&lt;P&gt;Here is one way to get the desired results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id Visit AE_free_text $;
cards;
1 1 1,4
2 1 1
3 1 2,4
4 1 1
5 1 1
6 1 3,9
7 1 3
8 1 2
;
run;

data _null_;
retain max 0 temp;
set have;
if _n_=1 then temp=countw(AE_free_text,',');
else do;
tempb=countw(AE_free_text,',');
max=max(temp,tempb,max);
end;
call symputx('total',max);
run;

data want(drop=ae_free_text i);
set have;
array text(*) text1-text&amp;amp;total;
do i=1 to dim(text);
 text(i)=input(scan(ae_free_text,i,','),8.);
end;
run;

proc print;
run;

proc transpose data=want out=want1(drop=_name_ where=(ae_num1 ne .)) prefix=ae_num;
/* use the new variable name in the WHERE= clause */
by id visit;
var text:;
run;

proc print data=want1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Jul 2025 18:09:28 GMT</pubDate>
    <dc:creator>Kathryn_SAS</dc:creator>
    <dc:date>2025-07-18T18:09:28Z</dc:date>
    <item>
      <title>Converting free text variable into numeric while expanding to long dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971109#M43383</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am seeking some help in converting a free text variable that contains multiple observations into a numeric variable while expanding to a long data set with potentially multiple rows per person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, in my "have" dataset, the AE_free_text includes codes for adverse events that were entered with codes in free text. When an individual had more than one adverse event at a study visit, the data entry person inputted this all on the same row. I want to have a long dataset so that each adverse event is on one line per participant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you! I look forward to learning from your responses.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Visit&lt;/TD&gt;&lt;TD&gt;AE_free_text&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1,4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2,4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3,9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;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lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
  input id Visit AE_free_text;
cards;
1 1 1,4
2 1 1
3 1 2,4
4 1 1
5 1 1
6 1 3,9
7 1 3
8 1 2
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971109#M43383</guid>
      <dc:creator>sofia_de_garay</dc:creator>
      <dc:date>2025-07-18T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting free text variable into numeric while expanding to long dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971118#M43386</link>
      <description>&lt;P&gt;Here is one way to get the desired results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id Visit AE_free_text $;
cards;
1 1 1,4
2 1 1
3 1 2,4
4 1 1
5 1 1
6 1 3,9
7 1 3
8 1 2
;
run;

data _null_;
retain max 0 temp;
set have;
if _n_=1 then temp=countw(AE_free_text,',');
else do;
tempb=countw(AE_free_text,',');
max=max(temp,tempb,max);
end;
call symputx('total',max);
run;

data want(drop=ae_free_text i);
set have;
array text(*) text1-text&amp;amp;total;
do i=1 to dim(text);
 text(i)=input(scan(ae_free_text,i,','),8.);
end;
run;

proc print;
run;

proc transpose data=want out=want1(drop=_name_ where=(ae_num1 ne .)) prefix=ae_num;
/* use the new variable name in the WHERE= clause */
by id visit;
var text:;
run;

proc print data=want1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jul 2025 18:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971118#M43386</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-07-18T18:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Converting free text variable into numeric while expanding to long dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971127#M43390</link>
      <description>&lt;P&gt;A simple DO loop will do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm="09"x truncover;
input ID $ Visit	 $ AE_free_text $;
datalines;
1	1	1,4
2	1	1
3	1	2,4
4	1	1
5	1	1
6	1	3,9
7	1	3
8	1	2
;

data want;
set have;
do i = 1 to countw(AE_free_text,",");
  AE_num = input(scan(AE_free_text,i,","),10.);
  output;
end;
drop i AE_free_text;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note how "have" data is posted readily usable in a DATA step with DATALINES. Please do so in the future,&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 18:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971127#M43390</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-18T18:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Converting free text variable into numeric while expanding to long dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971132#M43391</link>
      <description>Very helpful! Thank you for helping me learn.</description>
      <pubDate>Fri, 18 Jul 2025 20:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971132#M43391</guid>
      <dc:creator>sofia_de_garay</dc:creator>
      <dc:date>2025-07-18T20:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Converting free text variable into numeric while expanding to long dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971133#M43392</link>
      <description>Thank you! I learned a lot by going through your solution.</description>
      <pubDate>Fri, 18 Jul 2025 20:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-free-text-variable-into-numeric-while-expanding-to/m-p/971133#M43392</guid>
      <dc:creator>sofia_de_garay</dc:creator>
      <dc:date>2025-07-18T20:26:09Z</dc:date>
    </item>
  </channel>
</rss>

