Reputation: 87
i am new in SAS and I have a little problem. I try to choose 3. largest value from substring in names of files in directory. why i can't do that?
parent=directory
data files_and_folders;
keep num;
did=dopen("parent");
if dnum(did)>3 then do;
do i=1 to dnum(did);
names=int(substr(dread(did,i),9,8));
num=largest(3,names);
output;
end;
end;
output;
run;
returns
names:
20160322
20160323
20160324
20160325
20160325
but returns null value for num
thanks for help
Upvotes: 0
Views: 811
Reputation: 797
Your variable names
is a single number.
largest
gives you the largest value in a list of values.
e.g.
k=1
n=largest(k, 1, 2, 3, 4);
result: n = 4
k=2
n=largest(k, 1, 2, 3, 4);
result: n = 3
You are trying to get the third largest value out of a list of one. That results in a missing.
You need to output the whole file. Sort it by descending names
. Then limit it to the first three observations e.g. by obs=3 in a set statement
Upvotes: 1