开发者

Convert Numeric to Character 20

开发者 https://www.devze.com 2023-03-05 22:30 出处:网络
Hi I am building a dataset, but the data I am merging is in different formats. From the Excel sheet i import its in numeric 8, and the other 2 datasets im merging to are character 20, so I want to ch

Hi I am building a dataset, but the data I am merging is in different formats.

From the Excel sheet i import its in numeric 8, and the other 2 datasets im merging to are character 20, so I want to change the numeric 8 to char 20.

How can I chan开发者_开发知识库ge the variable acctnum, to char 20? (I also want to keep this as its name, as I presume a new variable will be created)

data WORK.T82APR;       
set WORK.T82APR;
rename F1 = acctnum f2 = tariff;
run;

proc contents data=T82APR;
run;


While this thread is already dead, I thought I'd way in and answer why the 14 digits conversion became in E notation.

Typically, or rather, unless otherwise specified, numeric formats in SAS use BEST12 format. As such, when a numeric value is longer than 12 characters (including any commas and periods), BEST12 chooses E notation as the best way to format the value.

The input function, in that case receives the formatted value put(acctnum, BEST12.). There would've been 2 ways around it.

Either use

input(put(acctnum, 14.), $20.);

Or, change the format of the variable using the format statement (directly in a data step or with proc datasets like) - this has the added benefit that if you open the table in SAS, you will see the 14 digits and not the scientific formatted value.

proc datasets library=work nolist;
    modify dsname;
        format acctnum 14.;
run;

Vincent


Try this:

data WORK.T82APR ;       
set WORK.T82APR;
acctnum = put(F1, $20.);
rename f2 = tariff;
run;

Ok, I didn't pay attention to your own rename statement, so I adjusted my answer to reflect that now.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号