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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

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
art297
Opal | Level 21

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

art297
Opal | Level 21

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 948 views
  • 0 likes
  • 3 in conversation