BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

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 😞

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

 

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=.

View solution in original post

4 REPLIES 4
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

Another danger of coding that uses the colon to indicate all variables beginning with a certain letter(s)!

--
Paige Miller
data_null__
Jade | Level 19

 

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=.
novinosrin
Tourmaline | Level 20

Goodness me. Thank you!!!!!!!!!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1381 views
  • 4 likes
  • 4 in conversation