<?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: Convert string variable to numeric in panel data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454588#M69991</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year $;
cards;
2011
2012
2013
2014
2015
2016
;;;;
run;

data want;
length year 8.;
set have(rename=(year=_year));
year=_year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Apr 2018 22:03:35 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-04-16T22:03:35Z</dc:date>
    <item>
      <title>Convert string variable to numeric in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454578#M69984</link>
      <description>&lt;P&gt;I imported an excel dataset to sas. There is a variable called "Year". The format is as following. When I want to merge this dataset with the other one, there is a warning that the length of "Year" in these two datasets are different. I tried to change the length for this imported dataset, but it failed. How can I convert it to numeric variable? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a3;&lt;BR /&gt;length year $ 4;&lt;BR /&gt;set a2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The dataset is a panel data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year&lt;/P&gt;&lt;P&gt;1990&lt;/P&gt;&lt;P&gt;1991&lt;/P&gt;&lt;P&gt;1992&lt;/P&gt;&lt;P&gt;1993&lt;/P&gt;&lt;P&gt;1990&lt;/P&gt;&lt;P&gt;1991&lt;/P&gt;&lt;P&gt;1992&lt;/P&gt;&lt;P&gt;1993&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 22:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454578#M69984</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2018-04-16T22:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454579#M69985</link>
      <description>&lt;P&gt;You can get there, but you can't change the existing variable from character to numeric while keeping the same name.&amp;nbsp; To work around that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;year_num&amp;nbsp;= input(year, 4.);&lt;/P&gt;
&lt;P&gt;drop year;&lt;/P&gt;
&lt;P&gt;rename year_num = year;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454579#M69985</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-16T21:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454580#M69986</link>
      <description>&lt;P&gt;But the new variable is missing value.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454580#M69986</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2018-04-16T21:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454582#M69987</link>
      <description>&lt;P&gt;Post your code and log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;solution, fully tested, that you can run on your system.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year $;
cards;
2011
2012
2013
2014
2015
2016
;;;;
run;

data want;

set have;

year_num = input(year, 4.);

drop year;

rename year_num = year;

run;

proc print data=want;run;
proc contents data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202889"&gt;@dapenDaniel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;But the new variable is missing value.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454582#M69987</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-16T21:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454583#M69988</link>
      <description>&lt;P&gt;Hi, the dataset is panel data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454583#M69988</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2018-04-16T21:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454586#M69990</link>
      <description>&lt;P&gt;Not sure how that affects this at all. Can you elaborate? Saying it doesn't work is not informative, it conveys no information about what didn't work, if you had an error, or what you even tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202889"&gt;@dapenDaniel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi, the dataset is panel data.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454586#M69990</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-16T21:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454588#M69991</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year $;
cards;
2011
2012
2013
2014
2015
2016
;;;;
run;

data want;
length year 8.;
set have(rename=(year=_year));
year=_year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 22:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454588#M69991</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-16T22:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454598#M69992</link>
      <description>&lt;P&gt;Sorry, I was misled by your title.&amp;nbsp; From your description of the problem, you don't need to convert anything to numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) Run a PROC CONTENTS on each data set that you want to merge, and find the longest length for the variable YEAR in any of the data sets.&amp;nbsp; Confirm that YEAR is character in all data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) Before trying to merge data sets, make sure your YEAR variables are left-hand justified.&amp;nbsp; That's easy to force:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year = left(year);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(3) In the DATA step that combines the data sets, add a LENGTH statement RIGHT AFTER the DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length year $ 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the longest length that you discovered in step 1.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 23:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454598#M69992</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-16T23:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454599#M69993</link>
      <description>&lt;P&gt;Length differences do not require conversion, just modify the lengths, in a data step for each variable to be the same and then combine them. Or convert them to numeric as shown where this is a non-issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new1;
length year $4.;
set old1;
run;

data new2;
length year $4.;
set old2;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS. Please do not modify your question to change it after the fact, it makes the question misleading. Post new information as a new post.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 23:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-string-variable-to-numeric-in-panel-data/m-p/454599#M69993</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-16T23:07:37Z</dc:date>
    </item>
  </channel>
</rss>

