<?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: Adding a character to the beginning of a character string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257678#M49494</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;The length already set to 6, no?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The current syntax is changing&amp;nbsp; 10101 to&amp;nbsp; &lt;SPAN&gt;01010, which then becomes _400802_part1=01, _400802_part2=01, _400802_part3=0. _400802_part3 should equal 01.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the data before the syntax:&lt;/P&gt;
&lt;TABLE class="table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;PatientID&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part2&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;140&lt;/TH&gt;
&lt;TD class="data"&gt;10101&lt;/TD&gt;
&lt;TD class="data"&gt;10&lt;/TD&gt;
&lt;TD class="data"&gt;10&lt;/TD&gt;
&lt;TD class="data"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the data after the syntax:&lt;/P&gt;
&lt;TABLE class="table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;PatientID&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part2&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;140&lt;/TH&gt;
&lt;TD class="data"&gt;01010&lt;/TD&gt;
&lt;TD class="data"&gt;01&lt;/TD&gt;
&lt;TD class="data"&gt;01&lt;/TD&gt;
&lt;TD class="data"&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;I'm sorry I don't understand your syntax well enough to trouble shoot this myself! Thanks again for your help.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2016 20:50:16 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2016-03-18T20:50:16Z</dc:date>
    <item>
      <title>Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257187#M49348</link>
      <description>&lt;P&gt;I am using an array to extract substrings from&amp;nbsp;a character string. In 4 of the 5 datasets, the string begins w/ a zero (e.g. 010101). In the&amp;nbsp;other&amp;nbsp;dataset, there is no leading zero (e.g. 10101). This causes problems for my array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I add a zero to the beginning of the character string for multiple variables? Another array no doubt...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 00:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257187#M49348</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-17T00:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257193#M49350</link>
      <description>Please provide a more clear picture of you problem by sharing the 'array' code you are having issues with along with a set of sample data</description>
      <pubDate>Thu, 17 Mar 2016 01:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257193#M49350</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2016-03-17T01:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257197#M49352</link>
      <description>&lt;P&gt;Just a guess :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data substrings;
/* ... */
set ds1 ds2 ds3(in=special) ds4 ds5;
if special then theString = cats("0", theString);
/* ... Extract substrings */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 02:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257197#M49352</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-17T02:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257202#M49353</link>
      <description>&lt;PRE&gt;DATA want_1;
   INPUT var1 $ var2 $;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
;
RUN;
&lt;/PRE&gt;
&lt;PRE&gt;DATA want_2;
	SET want_1;

	ARRAY original {2}  
	Var1 Var2;

	ARRAY new {2,3} $ 2 
	var1_part1	-  _var1_part3
	var2_part1	-  _var2_part3;

	DO i=1 to 2;
   	DO j=1 to 3;
      new{i,j} = substr(original{i}, 2*j-1);
   	END;
	
	DROP 
	i j;
RUN;&lt;/PRE&gt;
&lt;P&gt;The character string is supposed to be a maximum of 6 characters. The possible values are: 01 or 00 for each two digit pair. So, 010100 would be parsed into 3 new variables. Var1=01, Var2=01, Var3=00.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this one dataset, there is no leading zero, so the maximum string is 5 characters long. If the array substrings the first 2 characters, it will take 10, instead of 01.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19924"&gt;@FriedEgg﻿&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 03:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257202#M49353</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-17T03:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257203#M49354</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length str $6;
DO i=1 to 2;
	str = put(input(original{i}, best.), z6.);
   	DO j=1 to 3;
		new{i,j} = substr(str, 2*j-1);
		END;   	
	END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2016 03:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257203#M49354</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-17T03:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257238#M49360</link>
      <description>&lt;P&gt;Is it what you are looking for ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want_1;
   INPUT var1 $ var2 $;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
;
RUN;
data want;
 set want_1;
 array v{*} $ var: ;
 length temp $ 6;
 do i=1 to dim(v);
  temp=v{i};
  temp=translate(right(temp),'0',' ');
  v{i}=temp;
 end;
 drop temp i;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2016 09:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257238#M49360</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-17T09:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257306#M49373</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
   INPUT var $ @@;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
;
RUN;

DATA want;
   SET have;
   
   ARRAY xfr[3] $2 var_part1 - var_part3;
   
   CALL POKELONG( REPEAT('0',5) , ADDRLONG(xfr[1]) , 6 );
   
   CALL POKELONG( var , PTRLONGADD( ADDRLONG(xfr[1]) , 6 - LENGTHN(var) ) , LENGTHN(var) );
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2016 14:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257306#M49373</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2016-03-17T14:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257352#M49388</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19924"&gt;@FriedEgg﻿&lt;/a&gt;&amp;nbsp;Thanks for the assistance. A quick&amp;nbsp;clarifying question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;INPUT var $ @@;&amp;gt; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not familiar with this convention. When do the "@" symbols represent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I'm using SAS University Edition. I received the following error when I ran this code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA a2_pershealth_destring_qwb_2;
   SET a2_pershealth_replace_nulls;
   
   ARRAY xfr[3] $2 _400803_part1	-	_400803_part3;
   
   CALL POKELONG( REPEAT('0',5) , ADDRLONG(xfr[1]) , 6 );
   
   CALL POKELONG( var , PTRLONGADD( ADDRLONG(xfr[1]) , 6 - LENGTHN(_400803) ) , LENGTHN(_400803) );
RUN;&lt;/PRE&gt;
&lt;P&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;BR /&gt; 55 &lt;BR /&gt; 56 DATA a2_pershealth_destring_qwb_2;&lt;BR /&gt; 57 SET a2_pershealth_replace_nulls;&lt;BR /&gt; 58 &lt;BR /&gt; 59 ARRAY xfr[3] $2 _400803_part1-_400803_part3;&lt;BR /&gt; 60 &lt;BR /&gt; 61 CALL POKELONG( REPEAT('0',5) , ADDRLONG(xfr[1]) , 6 );&lt;BR /&gt; ________ ________&lt;BR /&gt; 251 68&lt;BR /&gt; &lt;FONT color="#FF0000"&gt;ERROR: The function POKELONG cannot be invoked when SAS is in the lockdown state.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR: The function ADDRLONG cannot be invoked when SAS is in the lockdown state.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR 251-185: The subroutine POKELONG is unknown, or cannot be accessed. Check your spelling. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; Either it was not found in the path(s) of executable images, or there was incorrect or missing subroutine descriptor &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; information.&lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR 68-185: The function ADDRLONG is unknown, or cannot be accessed.&lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT color="#FF0000"&gt; 62 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; 63 CALL POKELONG( var , PTRLONGADD( ADDRLONG(xfr[1]) , 6 - LENGTHN(_400803) ) , LENGTHN(_400803) );&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ________ ________&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; 251 68&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR: The function POKELONG cannot be invoked when SAS is in the lockdown state.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR: The function ADDRLONG cannot be invoked when SAS is in the lockdown state.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR 251-185: The subroutine POKELONG is unknown, or cannot be accessed. Check your spelling. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; Either it was not found in the path(s) of executable images, or there was incorrect or missing subroutine descriptor &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; information.&lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT color="#FF0000"&gt; ERROR 68-185: The function ADDRLONG is unknown, or cannot be accessed.&lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt; 64 RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 16:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257352#M49388</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-17T16:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257355#M49390</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;Thanks for this. It does the trick, to some degree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A value of&amp;nbsp;10100 is converted to&amp;nbsp;01010 (i.e. 01 01 0).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I adjust this code to produce a 6 digit string? Ideally,&amp;nbsp;10100 would be converted to 010100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, a value of 10101&amp;nbsp;is converted to 01010&amp;nbsp;(i.e. 01 01 0), when it should be 01 01 01.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 16:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257355#M49390</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-17T16:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257360#M49392</link>
      <description>Also, I'm fairly new to SAS and arrays. What is the purpose of the LENGTH statement (length temp $ 6;) in the array?</description>
      <pubDate>Thu, 17 Mar 2016 16:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257360#M49392</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-17T16:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257368#M49395</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36911"&gt;@_maldini_&lt;/a&gt;, My solution will not work with SAS University Edition.  As the ERROR message states, this product ships in a 'lockdown state' which disables the usage of the APP functions I have used.</description>
      <pubDate>Thu, 17 Mar 2016 17:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257368#M49395</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2016-03-17T17:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257369#M49396</link>
      <description>The LENGTH statement is there so that the RIGHT function will be able to justify the shorter strings to the proper place and then replace the spaces at the front of the string with '0'</description>
      <pubDate>Thu, 17 Mar 2016 17:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257369#M49396</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2016-03-17T17:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257372#M49398</link>
      <description>The @@ instructs SAS to read the input instructions repeatedly for the same line.  It is stated more clearly in the INPUT statement documentation.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146292.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146292.htm&lt;/A&gt;</description>
      <pubDate>Thu, 17 Mar 2016 17:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257372#M49398</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2016-03-17T17:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257487#M49445</link>
      <description>&lt;P&gt;Yes. Chang length as &amp;nbsp;LENGTH temp $ 6 ;&lt;/P&gt;
&lt;P&gt;If you want 6 digit string.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 00:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257487#M49445</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-18T00:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257678#M49494</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;The length already set to 6, no?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The current syntax is changing&amp;nbsp; 10101 to&amp;nbsp; &lt;SPAN&gt;01010, which then becomes _400802_part1=01, _400802_part2=01, _400802_part3=0. _400802_part3 should equal 01.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the data before the syntax:&lt;/P&gt;
&lt;TABLE class="table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;PatientID&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part2&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;140&lt;/TH&gt;
&lt;TD class="data"&gt;10101&lt;/TD&gt;
&lt;TD class="data"&gt;10&lt;/TD&gt;
&lt;TD class="data"&gt;10&lt;/TD&gt;
&lt;TD class="data"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the data after the syntax:&lt;/P&gt;
&lt;TABLE class="table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;PatientID&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part2&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;_400802_part3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;140&lt;/TH&gt;
&lt;TD class="data"&gt;01010&lt;/TD&gt;
&lt;TD class="data"&gt;01&lt;/TD&gt;
&lt;TD class="data"&gt;01&lt;/TD&gt;
&lt;TD class="data"&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;I'm sorry I don't understand your syntax well enough to trouble shoot this myself! Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 20:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257678#M49494</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-18T20:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257733#M49522</link>
      <description>&lt;P&gt;OK. Assuming I understand what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want_1;
   INPUT var1 $ var2 $;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
;
RUN;
data want;
 set want_1;
 array v{2} $ var1 var2 ;
 array v1{3} $ 2 var11-var13 ;
 array v2{3} $ 2 var21-var23 ;
 length temp $ 6;
 do i=1 to dim(v);
  temp=v{i};
  temp=translate(right(temp),'0',' ');
  v{i}=temp;

  if i=1 then do;
   k=0;
   do j=1 to 6 by 2;
    k+1;
	v1{k}=substr(v{i},j);
   end;
  end;

  if i=2 then do;
   k=0;
   do j=1 to 6 by 2;
    k+1;
	v2{k}=substr(v{i},j);
   end;
  end;


 end;

 drop temp i j k;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Mar 2016 03:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/257733#M49522</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-19T03:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258002#M49614</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;Thank you for your time and effort here. This code works great, but I should have been more clear. I have 53 variables. My example only included 2 variables. I was just trying to simplify things. The solution you proposed would require creating 53 arrays, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping I could simply add a leading 0 to the character strings, so that I could use the code/approach I have been using for the other time periods/data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the array I am using already, for all the other datasets, that already have a leading 0 in front of the character strings:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA want;
	* Setting the length of the variables to be 6 characters long;
	LENGTH 
	_400201
	_400202
	_400203
	_400204
	_400205
	_400206
	_400207
	_400208
	_400209
	_400210
        ...
	Up to 53 variables
	$6;

	SET have;

	ARRAY original {53}  
	_400201
	_400202
	_400203
	_400204
	_400205
	_400206
	_400207
	_400208
	_400209
	_400210
	...
        Up to 53 variables
        ;

	ARRAY new {53,3} $ 2 
	_400201_part1	-	_400201_part3
	_400202_part1	-	_400202_part3
	_400203_part1	-	_400203_part3
	_400204_part1	-	_400204_part3
	_400205_part1	-	_400205_part3
	_400206_part1	-	_400206_part3
	_400207_part1	-	_400207_part3
	_400208_part1	-	_400208_part3
	_400209_part1	-	_400209_part3
	_400210_part1	-	_400210_part3
	...&lt;BR /&gt;        Up to 53 variables
	;

	DO i=1 to 53;
   	DO j=1 to 3;
      new{i,j} = substr(original{i}, 2*j-1);
   	END;
	END;
	
	DROP 
	i j;
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Any other ideas&amp;nbsp;would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258002#M49614</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-21T16:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258111#M49659</link>
      <description>&lt;P&gt;OK. I would use proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want_1;
   INPUT var1 $ var2 $;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
;
RUN;
data temp;
 set want_1;
 array v{*} $ var1-var2 ;
 length temp $ 6 vname $ 40 value $ 2;
 n+1;
 do i=1 to dim(v);
  temp=v{i};
  temp=translate(right(temp),'0',' ');  
  vname=vname(v{i});
  k=0;
  do j=1 to 6 by 2;
    k+1;
	value=substr(temp,j,2);
	output;
   end;
 end;
drop i j ;
run;
proc transpose data=temp out=want(drop=_name_);
 by n ;
 var value;
 id vname k;
run;
data want;
 merge want_1 want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2016 01:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258111#M49659</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-22T01:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258116#M49662</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;Thank you again. We are getting there!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3 questions/issues:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The character strings in the original variable are of differing lengths. Ideally, the character string is 6 character long, after the leading 0 is added. So, &lt;SPAN&gt;400203=&lt;/SPAN&gt;10101 would become&amp;nbsp;010101, which would then become&amp;nbsp;400203_part1=01, 400203_part2=01, 400203_part3_01. This syntax does that! However, if the string is a different length, like 100, for example. The resutls are as follows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;400201&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002011&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;__4002012&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002013&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;100&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;01&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;00&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be:&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;400201&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002011&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;__4002012&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002013&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;100&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;01&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;00 or missing&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The other problem is w/ a value of 101 (i.e. Refused to respond). The results are as follows:&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;400203&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002031&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;__4002032&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;&lt;STRONG&gt;_4002033&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;
&lt;P&gt;101&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;01&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="111"&gt;
&lt;P&gt;01&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, the 3 resulting variables should probably be sett to missing ("").&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Where in this syntax can I change the vew variable names? I can't quite figure it out. It would be ideal, to sync w/ the code that follows it, if the names could be&amp;nbsp;_400201_part1, _400201_part2 _400201_part3 as opposed to&amp;nbsp;_4002011,&amp;nbsp;_4002012,&amp;nbsp;_4002013.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 02:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258116#M49662</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-22T02:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a character to the beginning of a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258123#M49665</link>
      <description>&lt;P&gt;So you don't want padding zero before it all the time ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want_1;
   INPUT var1 $ var2 $;
   DATALINES;
   10101      0 
   10101     100000 
   0         10100 
   10101      0
   100   101
;
RUN;
data temp;
 set want_1;
 array v{*} $ var1-var2 ;
 length temp $ 6 vname $ 40 value $ 2 kname $ 40;
 n+1;
 do i=1 to dim(v);
  temp=v{i};
  if temp not in ('100' '101') then temp=translate(right(temp),'0',' '); 
   else if temp='100' then temp=translate(temp,'0',' '); 
     else if temp='101' then call missing(temp); 
  vname=vname(v{i});
  k=0;
  do j=1 to 6 by 2;
    k+1;
    kname=cats('Part',k);
	value=substr(temp,j,2);
	output;
   end;
 end;
drop i j ;
run;
proc transpose data=temp out=want(drop=_name_) delimiter=_;
 by n ;
 var value;
 id vname kname;
run;
data want;
 merge want_1 want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2016 03:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-character-to-the-beginning-of-a-character-string/m-p/258123#M49665</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-22T03:03:17Z</dc:date>
    </item>
  </channel>
</rss>

