我想要以下内容:
data animals;
length string_in $50;
infile datalines dlm=",";
input string_in;
datalines;
rattlesnake honeybadger
lion eagle shark gorilla
mouse ape horse
;
run;
data animals_sorted;
set animals;
/* magic happens*/
put string_in;
run;
Output:
string_in: honeybadger rattlesnake
string_in: eagle gorilla lion shark
string_in: ape horse mouse
你有什么样的魔法进入这里?
我不知道任何SAS函数来对字符串中的单词进行排序,但SAS可以对ARRAY中的变量值进行排序.
data animals;
length string_in $50;
infile datalines dlm=",";
input string_in;
datalines;
rattlesnake honeybadger
lion eagle shark gorilla
mouse ape horse
;;;;
run;
data animals_sorted;
set animals;
array animals[10] $32 _temporary_;
call missing(of animals[*]);
do i = 1 to dim(animals) until(p eq 0);
call scan(string_in,i,p,l);
animals[i] = substrn(string_in,p,l);
end;
call sortc(of animals[*]);
length string_out $50;
string_out = catx(' ',of animals[*]);
drop i p l;
run;
proc print;
run;
Run Code Online (Sandbox Code Playgroud)