简体   繁体   English

SAS proc 格式中的其他值

[英]OTHER values in SAS proc format

I need to convert categorical data in variable REG into numeric and I am doing it as given below:我需要将变量 REG 中的分类数据转换为数字,我这样做如下所示:

proc format;
  value $Reg
    "To"=1
    "Al"=2
    "No"=3
    "Cu"=4
    other=5;
run;

data new;set old;
  format REG $Reg.;
run;

I tried the method in SAS proc format statement and the column REG is updating with 5 in all values (in all cases).我尝试了SAS proc 格式语句中的方法,并且列 REG 在所有值中都更新为 5(在所有情况下)。 May I know how to convert it properly?我可以知道如何正确转换它吗? Thanks for the help.谢谢您的帮助。

Works fine?工作正常?

proc format;
  value $Reg
    "To"=1
    "Al"=2
    "No"=3
    "Cu"=4
    other=5;
run;

data old;
input REG $;
datalines;
To
A1
No
Cu
;

data new;
  set old;
  format REG $Reg.;
run;

Be aware that the values in the Value Statement are case sensitive though.请注意,值声明中的值是区分大小写的。 That could be why.这可能就是原因。

You use a custom INFORMAT and INPUT statement to convert text to numbers.您使用自定义INFORMATINPUT语句将文本转换为数字。

Example:例子:

proc format;
  invalue Reg
    "To"=1
    "Al"=2
    "No"=3
    "Cu"=4
    other=5;

data have;
  input reg $ measure @@;
  datalines;
To 1.25 Moo 2.5 Al 3.2 Ti 5.6
Po 6.78 H 3.67 He 9.1 No 4.44
Cu 8.12 Cu 8.21 Yt 1.5
;

data want;
  set have;
  reg_num = input (reg, Reg.);
run;

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM