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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 759 views
  • 0 likes
  • 6 in conversation