Sum OF var list baffles me in an instance, What am I overlooking?
Please notice these
j=sum(of f: ); /*what's wrong with this. Am i missing something like me needing an appointment for my eyesight?*/
*j=sum(f1,f2); /*works as expected*/
And comment out for exclusive run and notice the results
data have;
input Document_Cd $ Document_number;
cards;
ABC 103013013013
BCD 103013013013
EFG 103013013013
ABC 103013013013
QRS 103013013013
QRS 103013013013
ABC 103013013013
DEF 103013013013
EFG 103013013014
;
data want;
do until(last.Document_number);
set have;
by Document_number;
if Document_Cd='DEF' then f1=1;
if Document_Cd='EFG' then f2=1;
end;
do until(last.Document_number);
set have;
by Document_number;
j=sum(of f:); /*what's wrong with this. Am i missing something like me needing an appointment for my eyesight?*/
*j=sum(f1,f2); /*works as expected*/
/*if f2 and sum(of f:)=1 then output; plz ignore this,as this a logic meant for another thread*/
output;
end;
*drop f:;
run;
My sincere apologies if i missed something so obvious, perhaps too much caffeine 😞
First.document_number
15 data want;
16 set have;
17 by Document_number;
18 if Document_Cd='DEF' then f1=1;
19 if Document_Cd='EFG' then f2=1;
20 put 'NOTE: ' (F:)(=);
21 run;
NOTE: FIRST.Document_number=1 f1=. f2=.
Hi,
it's strange but isn't "j=sum(of f:);" takes into account the firts.Document_number variable?
try something like that:
data want;
do until(last.Document_number);
set have;
by Document_number;
if Document_Cd='DEF' then f1=1;
if Document_Cd='EFG' then f2=1;
end;
array ff[*] f1-f2;
do until(last.Document_number);
set have;
by Document_number;
put _all_;
j=sum(of ff[*]); /*what's wrong with this. Am i missing something like me needing an appointment for my eyesight?*/
*j=sum(f1,f2); /*works as expected*/
/*if f2 and sum(of f:)=1 then output; plz ignore this,as this a logic meant for another thread*/
put _all_;
put;
output;
end;
*drop f:;
run;
all the best
Bart
Another danger of coding that uses the colon to indicate all variables beginning with a certain letter(s)!
First.document_number
15 data want;
16 set have;
17 by Document_number;
18 if Document_Cd='DEF' then f1=1;
19 if Document_Cd='EFG' then f2=1;
20 put 'NOTE: ' (F:)(=);
21 run;
NOTE: FIRST.Document_number=1 f1=. f2=.
Goodness me. Thank you!!!!!!!!!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.