<?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: Only want the last bit of a character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787692#M251734</link>
    <description>&lt;P&gt;It was just a part of the specifications I was given, but I also need a column with just the number. So I'll take that too and just concatenate 'Day' to it later.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Dec 2021 21:12:19 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2021-12-29T21:12:19Z</dc:date>
    <item>
      <title>Only want the last bit of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787685#M251727</link>
      <description>&lt;P&gt;I have the following column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 length visit $20.;
 input visit $22.;
 cards;
	INITIAL SCREENING
	MOCK CHMI DAY 1
	MOCK CHMI DAY 2
	MOCK CHMI DAY 3
	CHMI 1 DAY 1
	CHMI 1 DAY 5
	CHMI 1 DAY 15
	CHMI 2 DAY 1
	CHMI 2 DAY 5
	CHMI 2 DAY 20
	CHMI 2 DAY 27
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a column like such out of the first column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 length day $8.;
 input day $10.;
 cards;
	SCRN
	DAY 1
	DAY 2
	DAY 3
	DAY 1
	DAY 5
	DAY 15
	DAY 1
	DAY 5
	DAY 20
	DAY 27
 ;
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>Wed, 29 Dec 2021 20:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787685#M251727</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-12-29T20:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Only want the last bit of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787690#M251732</link>
      <description>&lt;P&gt;May I ask why you want "DAY 15" instead of just "15" or a numeric 15? That seems like whatever you do next, a numeric 15 would be easier to work with.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 21:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787690#M251732</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-29T21:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Only want the last bit of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787692#M251734</link>
      <description>&lt;P&gt;It was just a part of the specifications I was given, but I also need a column with just the number. So I'll take that too and just concatenate 'Day' to it later.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 21:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787692#M251734</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-12-29T21:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Only want the last bit of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787693#M251735</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311553"&gt;@mariko5797&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It was just a part of the specifications I was given, but I also need a column with just the number. So I'll take that too and just concatenate 'Day' to it later.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well you might want to ask if getting a numeric 15 is actually better than a character string. It is hard to imagine a situation where character DAY 15 would be superior to numeric 15. You might want to see if this can be changed to improve the process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But specs are specs. So here is my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length day $ 22;
    day=scan(visit,-1);
    if day='SCREENING' then day='SCRN';
    else day=cat('DAY ',day);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I note that if some sorting (or creating tables) of data set WANT is needed, then DAY 15 sorts ahead of DAY 2, and usually people don't want that. Numeric 15 always sorts after numeric 2 (assuming your sort is ascending).&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 13:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787693#M251735</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-30T13:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Only want the last bit of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787712#M251745</link>
      <description>&lt;P&gt;Here's another way of doing it with Proc SQL. Functions findw() and length() to derive start and end positions in substrn(), then compress() to keep only numbers, since you'll have "DAY (some number)" after substrbn() output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table want as 
select   visit
	,case when visit like '%SCREENING%' then 'SCRN'
	 else catx(" ","DAY",compress(substrn(visit,findw(visit, 'DAY'),length(visit)),'','A')) 
	 end as day length=8 
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 04:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-want-the-last-bit-of-a-character-variable/m-p/787712#M251745</guid>
      <dc:creator>ABprint</dc:creator>
      <dc:date>2021-12-30T04:12:04Z</dc:date>
    </item>
  </channel>
</rss>

