Sas 我想使用';if~else if';函数用于在第一个数据为字符时执行某些指令,在第一个数据为数字时执行其他指令

Sas 我想使用';if~else if';函数用于在第一个数据为字符时执行某些指令,在第一个数据为数字时执行其他指令,sas,Sas,在SAS中,如果第一个数据是字符,我想使用'if~ else if'函数执行一些指令,如果它们是数字,我想使用'if~ else if'函数执行其他指令 我尝试使用'if~ else if'语句,但不知道如何指定条件语句 在这部法典中 data pr1; input ~~~~ put profname$ course; cards; LEE 22 15 PARK ; run; 我想展示这个 profname course  LEE    22  PARK    15 我可以在“~~~”

在SAS中,如果第一个数据是字符,我想使用'if~ else if'函数执行一些指令,如果它们是数字,我想使用'if~ else if'函数执行其他指令

我尝试使用'if~ else if'语句,但不知道如何指定条件语句


在这部法典中

data pr1;
input ~~~~
put profname$ course;
cards;
LEE 22
15 PARK
;
run;
我想展示这个

profname course
 LEE    22  
 PARK    15

我可以在“~~~”中添加什么?

这里可能有一些巧妙的输入语句魔术,但我认为最简单、最清晰的解决方案是将两列作为字符数据读取,然后测试它们以查看哪一列包含哪些数据:

data pr1 (keep = profname course);

  * Declare PROFNAME as character and COURSE as numeric;
  length profname $ 20 course 8;

  * Read in two columns of data;
  input col1 $ col2 $

  if input(col1, ??best.) = . then do;
    * If COL1 cannot be converted to a number, assume it is a name;
    profname = col1;
    course = input(col2, ??best.);
  end; else do;
    * Otherwise assume COL2 is the name;
    profname = col2;
    course = input(col1, ??best.);
  end;

  cards;
LEE 22
15 PARK
  ;
run;

INPUT()
函数中的
??
修饰符会在无法处理值时抑制通常的警告。

您可以在SAS中处理它(Chris Long在下面提供了一个很好的解决方案),但修复源系统中问题产生的顺序是明智的。