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

i can do this using proc sql but my variables are 100 so it will take lot of time .Is their any other way so that i haven't to wright 100 variable in select statement

 

data a;

input s1 s2 s3 s4;

datalines;

1  2  3 4

2  2  4  5

9  9  9  9

;

run;

output

s1  s2  s3  s4

12 13  16   18

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data a;
input s1 s2 s3 s4;
datalines;
1 2 3 4
2 2 4 5
9 9 9 9
;

proc summary data=a;
var _numeric_;
output out=want(drop=_type_ _freq_) sum=;
run;

View solution in original post

5 REPLIES 5
mkeintz
PROC Star

This is where the various analysis and reporting PROCs in SAS excel.  In your case, it would be PROC SUMMARY:

 

data a;
  input s1 s2 s3 s4;
datalines;
1  2  3 4
2  2  4  5
9  9  9  9
run;
proc summary data=a  ;
  var s1-s4;
  output out=want (drop=_type_ _freq_)  sum=;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SASKiwi
PROC Star

Assuming your variables are named s1 to s100 something like this should work:

proc summary data = a sum;
  var s1 - s100;
  output out = a_sum
         sum = ;
run;
andreas_lds
Jade | Level 19

What do you need exactly as result? A dataset with the sums? Html-Output? The sums appended to the dataset you have?

Using proc summary is highly recommended, but if you can use IML, this maybe a good point to start, because it is designed to work with matrices.

proc iml;
   use work.a;
   read all var _num_ into have;
   close work.a;
   
   want = have[+,];
   print want;
quit;
LinusH
Tourmaline | Level 20

Transpose!

There are just a few scnarios when a wide table make s sense.

A long table structure is easier to query, optimizes storage etc.

Data never sleeps
Ksharp
Super User
data a;
input s1 s2 s3 s4;
datalines;
1 2 3 4
2 2 4 5
9 9 9 9
;

proc summary data=a;
var _numeric_;
output out=want(drop=_type_ _freq_) sum=;
run;
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
  • 5 replies
  • 1930 views
  • 0 likes
  • 6 in conversation