<?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: Need to merge and rename character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630740#M186762</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;study_id is a character variable and ID and PID are numeric.&lt;/P&gt;
&lt;P&gt;The Cats function is not working&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; web.new;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ESC.old;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;id_new=cat(id,pid,study_id);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You say CATS is not working but show CAT. They are two different functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of a bunch of if/then you might consider the COALESCE, for numeric values, or COALESCEC for character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coalesce(PID, 0) will return the value of PID if not missing and 0 if PID is missing. So you might be looking for something like:&lt;/P&gt;
&lt;PRE&gt;data web.new;
   set ESC.old;
   length id_new $ 14;
   id_new=cats(coalesce(id,0),coalesce(pid,0),coalescec(study_id,'0') );
run;
&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Mar 2020 20:12:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-09T20:12:37Z</dc:date>
    <item>
      <title>Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630621#M186701</link>
      <description>&lt;P&gt;I have three different variables&lt;/P&gt;
&lt;P&gt;ID: 0000 (4 numbers)&lt;/P&gt;
&lt;P&gt;PID: 0000 (4 numbers)&lt;/P&gt;
&lt;P&gt;and Study ID BOT000 (three numbers and three characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make a new variable called ID_NEW&lt;/P&gt;
&lt;P&gt;I am trying to merge all three to one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*DO; IF PID = . THEN PID = 0; END;&lt;/P&gt;
&lt;P&gt;DO; IF ID = . THEN ID = 0; END;&lt;/P&gt;
&lt;P&gt;DO; IF Study_ID=. then Study_id=0; End;&lt;/P&gt;
&lt;P&gt;DO; ID_NEW = ID+PID+STUDY_ID; END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630621#M186701</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-03-09T13:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630624#M186704</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have three different variables&lt;/P&gt;
&lt;P&gt;ID: 0000 (4 numbers)&lt;/P&gt;
&lt;P&gt;PID: 0000 (4 numbers)&lt;/P&gt;
&lt;P&gt;and Study ID BOT000 (three numbers and three characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make a new variable called ID_NEW&lt;/P&gt;
&lt;P&gt;I am trying to merge all three to one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*DO; IF PID = . THEN PID = 0; END;&lt;/P&gt;
&lt;P&gt;DO; IF ID = . THEN ID = 0; END;&lt;/P&gt;
&lt;P&gt;DO; IF Study_ID=. then Study_id=0; End;&lt;/P&gt;
&lt;P&gt;DO; ID_NEW = ID+PID+STUDY_ID; END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show the types of all variables used. The operator + is only valid for numeric variables, if you want to concatenate strings, you should use one of the cat-functions. So Maybe you can solve the problem by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* before data step */ 
options missing = "0";

/* in a data step */
id_new=cats(id, pid, study_id);

/* after data step */
options missing=".";
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630624#M186704</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-09T13:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630628#M186706</link>
      <description>&lt;P&gt;study_id is a character variable and ID and PID are numeric.&lt;/P&gt;
&lt;P&gt;The Cats function is not working&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; web.new;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ESC.old;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;id_new=cat(id,pid,study_id);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630628#M186706</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-03-09T13:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630632#M186707</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;study_id is a character variable and ID and PID are numeric.&lt;/P&gt;
&lt;P&gt;The Cats function is not working&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; web.new;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ESC.old;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;id_new=cat(id,pid,study_id);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not force SAS to guess how to define a new variable, you might now like the decision it makes. Define the type and storage length yourself.&amp;nbsp; So if ID is length $10 and you want to convert the two numbers to four digits each then ID_NEW needs to be length $18.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not force SAS to guess how to convert values between types, you might not like the decision it makes.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length id_new $18.
id_new=cats(id,put(pid,Z4.),put(study_id,Z4.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630632#M186707</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-09T13:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630654#M186716</link>
      <description>&lt;P&gt;the cats function is not recognized in my dataset...cant seem to get it to work&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 15:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630654#M186716</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-03-09T15:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630659#M186720</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the cats function is not recognized in my dataset...cant seem to get it to work&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Datasets do not have functions.&lt;/P&gt;
&lt;P&gt;What version of SAS are you running?&amp;nbsp; It should appear at the start of the SAS log.&amp;nbsp; Or look at the value of the automatic macro variables SYSVER and SYSVLONG.&lt;/P&gt;
&lt;PRE&gt;12867  %put SYSVER  =&amp;amp;SYSVER  ;
SYSVER  =9.4
12868  %put SYSVLONG=&amp;amp;SYSVLONG;
SYSVLONG=9.04.01M5P091317&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 15:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630659#M186720</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-09T15:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630740#M186762</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;study_id is a character variable and ID and PID are numeric.&lt;/P&gt;
&lt;P&gt;The Cats function is not working&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; web.new;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ESC.old;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;id_new=cat(id,pid,study_id);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You say CATS is not working but show CAT. They are two different functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of a bunch of if/then you might consider the COALESCE, for numeric values, or COALESCEC for character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coalesce(PID, 0) will return the value of PID if not missing and 0 if PID is missing. So you might be looking for something like:&lt;/P&gt;
&lt;PRE&gt;data web.new;
   set ESC.old;
   length id_new $ 14;
   id_new=cats(coalesce(id,0),coalesce(pid,0),coalescec(study_id,'0') );
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 20:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630740#M186762</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-09T20:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need to merge and rename character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630803#M186789</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;study_id is a character variable and ID and PID are numeric.&lt;/P&gt;
&lt;P&gt;The Cats function is not working&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; web.new;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; ESC.old;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;id_new=cat(id,pid,study_id);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't see the options-statement i posted, if you don't change the way missing numerics are displayed, cat[s] will simply omit the variable while concatenating.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 06:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-merge-and-rename-character-to-numeric/m-p/630803#M186789</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-10T06:13:11Z</dc:date>
    </item>
  </channel>
</rss>

