<?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: changing character to numeric in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73765#M21391</link>
    <description>Nice that you gave more information about your problem. In merge you should state all "by" columns, like:&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
merge one two;&lt;BR /&gt;
by Name Date Time Class Route Place Arrival;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
For time it's simple, if you have time in HH:MM format use input function to create numeric version of TIME variable:&lt;BR /&gt;
timenum=input(timechar,time5.);&lt;BR /&gt;
For Arrival/Place you have to be more specific - if both are numbers, but one stored as a character, use the same input function but with different informat (like best.). If not, and there is relation like 1-Orlando etc., then it's a bigger issue.</description>
    <pubDate>Tue, 21 Sep 2010 21:30:31 GMT</pubDate>
    <dc:creator>scyth</dc:creator>
    <dc:date>2010-09-21T21:30:31Z</dc:date>
    <item>
      <title>changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73764#M21390</link>
      <description>I am trying to append two datasets (one and two) that have 6 columns:- Class,Route,Date,Time,Name,Place and Arrival&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In file one, Time,Arrival and Place are character and these variables are Numeric in the data set two. &lt;BR /&gt;
&lt;BR /&gt;
In the dataset two the informat and the format for these numeric variables is:Time8. (for Arrival),Date9. (for Date) and Time8. (for Time). The other three variables viz. Route,Class and Name are character in both the datasets. &lt;BR /&gt;
&lt;BR /&gt;
I use the code:-&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
	merge one two;&lt;BR /&gt;
	by Name;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and get the error that Time,arrival and Place are defined as both character and numeric.&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
Kindly Suggest.&lt;BR /&gt;
Sid</description>
      <pubDate>Tue, 21 Sep 2010 20:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73764#M21390</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-21T20:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73765#M21391</link>
      <description>Nice that you gave more information about your problem. In merge you should state all "by" columns, like:&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
merge one two;&lt;BR /&gt;
by Name Date Time Class Route Place Arrival;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
For time it's simple, if you have time in HH:MM format use input function to create numeric version of TIME variable:&lt;BR /&gt;
timenum=input(timechar,time5.);&lt;BR /&gt;
For Arrival/Place you have to be more specific - if both are numbers, but one stored as a character, use the same input function but with different informat (like best.). If not, and there is relation like 1-Orlando etc., then it's a bigger issue.</description>
      <pubDate>Tue, 21 Sep 2010 21:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73765#M21391</guid>
      <dc:creator>scyth</dc:creator>
      <dc:date>2010-09-21T21:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73766#M21392</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
When I use the code:-&lt;BR /&gt;
&lt;BR /&gt;
data char(drop=time_num place_num arrival_num) / view=char;&lt;BR /&gt;
	set week2 (rename=(time=time_num place=place_num arrival=arrival_num));&lt;BR /&gt;
		time_num=INPUT(time,time9.);&lt;BR /&gt;
		place_num=INPUT(place,time8.);  &lt;BR /&gt;
		arrival_num= INPUT(arrival,time8.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Actually, what I want is to convert the three variables Time, Place and Arrival in week 2 into numeric (as other variables are character type in both data sets) so as to merge the data set week 2 with the dataset week 1 (week 1 has these variables as numeric). After using the above code , I use the code:-&lt;BR /&gt;
&lt;BR /&gt;
data sdsd;&lt;BR /&gt;
	MERGE char week1;&lt;BR /&gt;
	by TIME PLACE ARRIVAL CLASS ROUTE DATE NAME;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The code runs successfully without any error. But  there are blank spaces in the merged dataset 'sdsd' with blanks occuring for the dataset 'char' in the three converted variables.&lt;BR /&gt;
&lt;BR /&gt;
Kindly suggest.&lt;BR /&gt;
&lt;BR /&gt;
Kritanjli.</description>
      <pubDate>Wed, 22 Sep 2010 05:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73766#M21392</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T05:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73767#M21393</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Maybe you can give an example how your do those character values for these variables look like, especially to those places where blanks occur?&lt;BR /&gt;
&lt;BR /&gt;
Ieva</description>
      <pubDate>Wed, 22 Sep 2010 05:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73767#M21393</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2010-09-22T05:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73768#M21394</link>
      <description>data two has the format:-&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
#	Variable	Type	Len&lt;BR /&gt;
6	ARRIVAL	Char	8&lt;BR /&gt;
4	TIME  	Char	8&lt;BR /&gt;
5	PLACE     Char	5&lt;BR /&gt;
3	CLASS	Char	5&lt;BR /&gt;
1	NAME	Char	10&lt;BR /&gt;
2	CITY  	Char	4&lt;BR /&gt;
&lt;BR /&gt;
data one:-&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
#	Variable	Type	Len	Format	Informat	    Label&lt;BR /&gt;
6	ARRIVAL	Num	8	TIME8.	ARRIVAL8.   ARRIVAL&lt;BR /&gt;
1	TIME 	Num	8	DATE9.	TIME9.	    DATE&lt;BR /&gt;
4	PLACE	Num	8	TIME8.	PLACE8.	    DEPART&lt;BR /&gt;
5	CLASS	Char	4	$4.	            $4.	    CLASS&lt;BR /&gt;
3	NAME	Char	5	$5.	            $5.	    NAME&lt;BR /&gt;
2	CITY 	Char	5	$5.	            $5.	    CITY&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I want to merge data one and data two.  Kindly suggest.&lt;BR /&gt;
&lt;BR /&gt;
Kritanjli.</description>
      <pubDate>Wed, 22 Sep 2010 06:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73768#M21394</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T06:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73769#M21395</link>
      <description>No errors, but blanks in the values? Sounds like you are talking about the formatted values. Otherwise you should have gotten some kind of note/warning messages.&lt;BR /&gt;
&lt;BR /&gt;
Let me go out on a limb here: is it the missing leading zero in a time value that bothers you? You want 09:10:15 instead of 9:10:15? If so then create a format somewhat like&lt;BR /&gt;
[pre]&lt;BR /&gt;
 proc format;&lt;BR /&gt;
   picture ztime low-high = '%0H:%0M:%0S' (datatype=time) ;&lt;BR /&gt;
 run ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Assign this format to your time values&lt;BR /&gt;
[pre]&lt;BR /&gt;
format time place arrival ztime. ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
If this is not the problem you are facing then please explain in more detail what "there are blank spaces in .... for the dataset 'char' ...." means exactly.</description>
      <pubDate>Wed, 22 Sep 2010 07:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73769#M21395</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-09-22T07:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73770#M21396</link>
      <description>I would write the character of the two datasets and the code I used and the Log that I get as -&lt;BR /&gt;
&lt;BR /&gt;
data week 2 has the format:-&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
# Variable                       Type                         Len&lt;BR /&gt;
6 ARRIVAL                      Char                           8&lt;BR /&gt;
4 DATE                           Char                           8&lt;BR /&gt;
5 DEPART                       Char                          5&lt;BR /&gt;
3 CLASS                         Char                           5&lt;BR /&gt;
1 NAME                           Char                         10&lt;BR /&gt;
2 CITY                              Char                          4&lt;BR /&gt;
&lt;BR /&gt;
data week 1:-&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
# Variable           Type                      Len              Format/Informat                   &lt;BR /&gt;
6 ARRIVAL         Num                       8                  TIME8.                            &lt;BR /&gt;
1 DATE              Num                       8                  TIME9.                              &lt;BR /&gt;
4 DEPART          Num                       8                  TIME8.                             &lt;BR /&gt;
5 CLASS            Char                       4                   $4.                                  &lt;BR /&gt;
3 NAME             Char                       5                    $5.                                 &lt;BR /&gt;
2 CITY                Char                       5                   $5.                                   &lt;BR /&gt;
&lt;BR /&gt;
I use the code:-&lt;BR /&gt;
&lt;BR /&gt;
data char(drop=date_num depart_num arrival_num) / view=char;&lt;BR /&gt;
    set week 2 (rename=(date=date_num depart=depart_num arrival=arrival_num));&lt;BR /&gt;
        date_num=INPUT(date,date9.);&lt;BR /&gt;
        depart_num=INPUT(depart,time8.); &lt;BR /&gt;
        arrival_num= INPUT(arrival,time8.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
LOG:-&lt;BR /&gt;
&lt;BR /&gt;
 Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;
      311:18   311:24   312:20   312:26   313:22   313:28&lt;BR /&gt;
&lt;BR /&gt;
Then I use code:-&lt;BR /&gt;
data sdsd;&lt;BR /&gt;
    MERGE char week1;&lt;BR /&gt;
    by ORIGIN DRIVER DESTINATION DATE DEPART ARRIVAL;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
LOG:-&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 24 observations read from the data set WORK.WEEK2.&lt;BR /&gt;
NOTE: There were 24 observations read from the data set WORK.CHAR.&lt;BR /&gt;
NOTE: There were 24 observations read from the data set WORK.WEEK1.&lt;BR /&gt;
NOTE: The data set WORK.SDSD has 48 observations and 6 variables.&lt;BR /&gt;
&lt;BR /&gt;
Next, I use the command:-&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA=sdsd;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
But, the output does not give me the entries for the new data "char" for the three variables that I converted from character to numeric.&lt;BR /&gt;
&lt;BR /&gt;
Kindly suggest, where I'm making a mistake.&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
Krit</description>
      <pubDate>Wed, 22 Sep 2010 08:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73770#M21396</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T08:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73771#M21397</link>
      <description>You have the variable names wrong in your view.&lt;BR /&gt;
On the SET statement you do the rename with the _num suffix. Do that with a _char suffix (in order to keep the suffix meaningful).&lt;BR /&gt;
On your var=INPUT(...) statements you should have the target names (i.e. those that you want to keep) on the left side.&lt;BR /&gt;
Things like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
date    = input(date_char ...) ;&lt;BR /&gt;
depart  = input(depart_char ...) ;&lt;BR /&gt;
arrival = input(arrival_char ... );&lt;BR /&gt;
[/pre]&lt;BR /&gt;
and then drop the _char suffix variables.</description>
      <pubDate>Wed, 22 Sep 2010 10:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73771#M21397</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-09-22T10:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73772#M21398</link>
      <description>Hi Sid&lt;BR /&gt;
&lt;BR /&gt;
To post references for posting the same question in different forums would be kind of courtesy to the ones giving you their time to answer.&lt;BR /&gt;
&lt;BR /&gt;
So: Same question already posted here by 2 different people. It seems to be a study excercise:&lt;BR /&gt;
&lt;A href="http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/7ee599125d81eb80?hl=en#" target="_blank"&gt;http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/7ee599125d81eb80?hl=en#&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/df7183cf64b52297/f31e01b38fbd3866?hl=en#f31e01b38fbd3866" target="_blank"&gt;http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/df7183cf64b52297/f31e01b38fbd3866?hl=en#f31e01b38fbd3866&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Patrick</description>
      <pubDate>Wed, 22 Sep 2010 10:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73772#M21398</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-09-22T10:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: changing character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73773#M21399</link>
      <description>try these codes&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data  Week2_1 (drop = DATE ARRIVAL DEPART);&lt;BR /&gt;
set  Week2;&lt;BR /&gt;
DATE_1 = input(DATE, ANYDTDTE10.);&lt;BR /&gt;
format DATE_1 date9.;&lt;BR /&gt;
ARRIVAL_1 = input(ARRIVAL, anydttme8.);&lt;BR /&gt;
format ARRIVAL_1  time8.;&lt;BR /&gt;
DEPART_1 = input(DEPART, anydttme8.);&lt;BR /&gt;
format DEPART_1  time8.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data  Week2_2;&lt;BR /&gt;
set  Week2_1;&lt;BR /&gt;
rename &lt;BR /&gt;
DATE_1 = DATE&lt;BR /&gt;
ARRIVAL_1 = ARRIVAL&lt;BR /&gt;
DEPART_1 = DEPART;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Data new;&lt;BR /&gt;
set Week1 Week2_2;  /* u r trying to append 2 files not merge right?*/&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
so now data set new should have all the observations</description>
      <pubDate>Wed, 22 Sep 2010 12:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-character-to-numeric/m-p/73773#M21399</guid>
      <dc:creator>samHT</dc:creator>
      <dc:date>2010-09-22T12:48:27Z</dc:date>
    </item>
  </channel>
</rss>

