BookmarkSubscribeRSS Feed
traceykelisha
Calcite | Level 5

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? 

 

4 REPLIES 4
Reeza
Super User

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. 

traceykelisha
Calcite | Level 5
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.
traceykelisha
Calcite | Level 5

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

 

 

atzamis
Obsidian | Level 7

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1264 views
  • 0 likes
  • 3 in conversation