turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- creating sum variables

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-19-2015 12:45 AM

I'm really new to SAS and would appreciate some help..

Accepted Solutions

Solution

04-19-2015
06:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-19-2015 06:59 PM

Like Fareeza said, such stats are easily calculated using one of the SAS procs.

Your problem clearly looks like a homework assignment and, if the solution code is your own, your calculation formula is wrong. You would definitely have to capture and use N somewhere in your formula.

You can easily include some minor proc sql code to capture and store the desired numbers in macro variables. And you can print them in your log so that you follow your prof's preferred approach. e.g.:

proc sql;

select count(*),sum(x),sum(y),sum(x**2),sum(y**2)

into :n,:xsum,:ysum,:x2sum,:y2sum

from Question1

;

quit;

%put &n;

%put &xsum;

%put &ysum;

%put &x2sum;

%put &y2sum;

Conversely, Using the proc print approach, you could do something like the following to get the desired N:

proc print data=Question1 n='# of cases:' noobs;

sum x y x2 y2;/*get sums of variables from this table to use in your analysis-I like this way best since I can see the actual calculations*/

run;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-19-2015 09:45 AM

Hope this is what you are expecting

data XY;

input x y;

ord=1;

datalines;

18 23

13 20

18 18

15 16

10 14

12 11

8 10

4 7

7 6

3 4

;

run;

proc sort data=xy;

by ord;

run;

data want;

set xy;

by ord;

if first.ord then do;

sumx=x;

sumy=y;

end;

else do;

sumx+x;

sumy+y;

end;

run;

Thanks,

Jag

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-19-2015 10:37 AM

Given your example, what do you want the result to look like?

Solution

04-19-2015
06:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-19-2015 06:59 PM

Like Fareeza said, such stats are easily calculated using one of the SAS procs.

Your problem clearly looks like a homework assignment and, if the solution code is your own, your calculation formula is wrong. You would definitely have to capture and use N somewhere in your formula.

You can easily include some minor proc sql code to capture and store the desired numbers in macro variables. And you can print them in your log so that you follow your prof's preferred approach. e.g.:

proc sql;

select count(*),sum(x),sum(y),sum(x**2),sum(y**2)

into :n,:xsum,:ysum,:x2sum,:y2sum

from Question1

;

quit;

%put &n;

%put &xsum;

%put &ysum;

%put &x2sum;

%put &y2sum;

Conversely, Using the proc print approach, you could do something like the following to get the desired N:

proc print data=Question1 n='# of cases:' noobs;

sum x y x2 y2;/*get sums of variables from this table to use in your analysis-I like this way best since I can see the actual calculations*/

run;