BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mdoddala
Obsidian | Level 7
data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;
proc print;
run;

data dummy1 (drop= q1--q5);
set dummy;
sum=sum(of_numeric_);
proc print;
run;

 

 

Need help with this code. I'm getting a blank output for the sum variable.

Thanks,
Mohan

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @mdoddala   Your code is fine and works well.. just a typo

 


data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;


data dummy1 (drop= q1--q5);
set dummy;
sum=sum(of _numeric_);
run;

The typo was 

sum=sum(of_numeric_);

 instead of 

sum=sum(of _numeric_);

View solution in original post

19 REPLIES 19
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Communities 🙂

 

Use an Array Statement to get all numeric variables and sum over the array

 

data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;

data dummy1;
   set dummy;
   array nums[*] _numeric_; 
   sum=sum(of nums[*]);
run;

proc print;
run;   

 

mdoddala
Obsidian | Level 7

Is it wrong to use of_numeric_?

PeterClemmensen
Tourmaline | Level 20

No. Not at all. Just an alternative 🙂 Your code works well too if you correct a small typo:

 

data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;

data dummy1;
   set dummy;
   sum=sum(of _numeric_);
run;

proc print;
run;
novinosrin
Tourmaline | Level 20

Hi @mdoddala   Your code is fine and works well.. just a typo

 


data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;


data dummy1 (drop= q1--q5);
set dummy;
sum=sum(of _numeric_);
run;

The typo was 

sum=sum(of_numeric_);

 instead of 

sum=sum(of _numeric_);
mdoddala
Obsidian | Level 7

Thank you so much @novinosrin 🙂 for pointing out my mistake.

mdoddala
Obsidian | Level 7

Also @novinosrin , what are the other ways I can use of _numeric_? Is it possible to use in proc print statement? Please let me know. Thank you very much again for your help:) 

novinosrin
Tourmaline | Level 20

I assume other ways meaning other scenarios 

 

Yes anywhere variable lists usage is permitted

 

for example

 

proc print data=dummy;
var _numeric_;
run;
proc print data=dummy(keep=_numeric_);
run;

and so on and so forth

novinosrin
Tourmaline | Level 20
data dummy;
input q1 q3 q4 q2 q6$ bu$ q5;
cards;
1 2 3 5 sa an 3
2 4 3 6 sm sa 4
6 5 3 8 cb na 3
;


data dummychar(keep=_char_) dummynumeric(keep=_numeric_);
set dummy;
run;
mdoddala
Obsidian | Level 7
Thank you so much @novinosrin for enlightening me:)
Andygray
Quartz | Level 8

Hello @mdoddala 

Acknowledge @novinosrin  's answer by marking the answer as accepted though I don't think somebody who is prolific with super user status cares for credits. But that's ethic. That was a sharp catch.

mdoddala
Obsidian | Level 7

Also @novinosrin, what books do you suggest for beginners like me to become an expert in SAS programming and how long will it take to become an expert?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 19 replies
  • 3621 views
  • 11 likes
  • 6 in conversation