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
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_);
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;
Is it wrong to use of_numeric_?
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;
Thank you @PeterClemmensen 🙂
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_);
Thank you so much @novinosrin 🙂 for pointing out my mistake.
You are welcome!
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:)
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
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;
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.
I just did that:)
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?
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.