在SAS中,我想使用'if ~ else if'函数在第一个数据是字符时执行一些指令,如果它们是数字,则执行其他指令。
我尝试使用"if ~ else if"语句,但我不知道如何指定条件语句。
在此代码中,
data pr1;
input ~~~~
put profname$ course;
cards;
LEE 22
15 PARK
;
run;
我想展示这个。
profname course
LEE 22
PARK 15
我可以在"~~~"中输入什么?
在这里你可以
做一些聪明的 INPUT 语句魔法,但我认为最简单、最清晰的解决方案是在两列中读取字符数据,然后测试它们以查看哪一列包含哪些数据:
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()
函数中的??
修饰符在无法处理值时禁止显示通常的警告。