Help using Base SAS procedures

Summation

Reply
New Contributor
Posts: 3

Summation

Good day,

 

How do  i write  a sas code that wiill;

1. Utilize a total i obtained for a variable(such as nF=total number of females in a gender column) via proc mean in the dataset i want to create follwoing that command?

2. sum of squares for negative differences of females that may extend from i=1 to nF? 

 

Super User
Posts: 17,898

Re: Summation

1. Store results in a table and merge the tables. Or still store it in a table, create a macro variable with the information and use that in future steps. 

 

2. Your requirements are unclear. Proc Means does some differences or errors. Check all the statistics available in the documentation. 

New Contributor
Posts: 3

Re: Summation

re your first response, when you say store the table do you mean output it to an external file? wouldnt i then have to import the table back into sas to use it in future calculations?
not sure how to create a macrovariable especially if i want the code to run automatically despite changes in the numbers from the original data file.
New Contributor
Posts: 3

Re: Summation

Re your second response i will try to clarify my question. Kindly find attached the simplified version of what i want to ask.IMG_sasquest.jpg

 

 

Occasional Contributor
Posts: 10

Re: Summation

Hi, 

I do not know if this what you are looking for (based on the istructions in the notebook - picture, it is counting status M) :

 

DATA TEST;
INPUT MARITAL_STATUS $ INITIAL_BP FINAL_BP;
DATALINES;
M 60 70
S 80 60
C 90 70
C 100 60
M 120 80
S 141 90
S 80 120
S 90 110
S 115 110
M 117 112
C 114 112
C 105 96
M 103 87
M 107 110
S 106 110
;

 

PROC SQL ;
SELECT COUNT(*) INTO :NS FROM TEST WHERE MARITAL_STATUS='S';
SELECT COUNT(*) INTO :NNS FROM TEST WHERE MARITAL_STATUS='S' & SUM(INITIAL_BP,-FINAL_BP)<0 ;
QUIT;

 

%PUT SINGLES &NS. ;  /*can be omitted*/
%PUT SINGLES NEGATIVE &NNS. ; /*can be omitted*/


DATA TEST;
SET TEST;
     IF SUM(INITIAL_BP,-FINAL_BP)<0 & MARITAL_STATUS='S' THEN
                   JIF=(INITIAL_BP**2/SUM(INITIAL_BP,-FINAL_BP)**3)/(&NS.*&NNS.);
RUN;

 

PROC PRINT DATA=TEST;
RUN;


PROC MEANS DATA=TEST N SUM;
      VAR JIF;
RUN;

 

 

 

Obs MARITAL_STATUS INITIAL_BP FINAL_BP JIF 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
M6070.
S8060.
C9070.
C10060.
M12080.
S14190.
S80120-0.00556
S90110-0.05625
S115110.
M117112.
C114112.
C10596.
M10387.
M107110.
S106110-9.75347

 

 

 

Analysis Variable :
JIF N Sum
3-9.8152778
Ask a Question
Discussion stats
  • 4 replies
  • 186 views
  • 0 likes
  • 3 in conversation