Ivy Murphy
Ivy Murphy

Reputation: 9

SAS Calculate the proportion of two datasets

I got two datasets, assume one has 100 observation and the other has 50. So, the proportion of these two datasets is 100/50=2. Does anyone know how to calculate this number in SAS and save it for later programming? Thank you in advance!

Upvotes: 0

Views: 157

Answers (1)

Rick Paddock
Rick Paddock

Reputation: 95

There are loads of ways to get dataset obs, such as: proc SQL insert into, proc contents output, using SASHELP tables, using the end= statement in a datastep.

However I like doing it with SAS macro vars (using %let and %sysfunc) as it makes you like a badass. You want to look like a badass right? Something like this (I don't have SAS open in front of me to test so the syntax might be slightly wrong):

%macro getobs(mydata);
    %let data_open=%sysfunc(OPEN(&mydata.,IN));
    %let NOBS_&mydata.=%sysfunc(ATTRN(&data_open,NLOBS));
    %let data_close=%sysfunc(CLOSE(&data_open));
%mend;

Then you should be able to use the NOBS_&mydata vars to get your required proportion value (although you might need a %global NOBS_&mydata. statement in the macro .... I'm not sure). Something like:

%let proportion = &NOBS_data1 / &NOBS_data2;

Play around with it and see what you come up with.

Upvotes: 0

Related Questions