data neg_prices;
set homework_one;
if price<0 then price_type = 'neg'; * create new label: negative when price is less than zero and otherwise;
else price_type = 'pos';
run;
proc means data=neg_prices n;a
class price_type; * get number of observations for negative prices;
var price;
run;
I have a proc means output as shown below:
I want to extract N from the table and evaluate N for neg/(N for neg + N for pos), pretty much get the proportion of negative data from total data. How to go about this problem?
SAS Output
| 594 |
| 69478 |
You need to direct your output to a data set and then you can use it in further steps.
*Create summary statistics for a dataset by a 'grouping' variable and store it in a dataset;
*Generate sample fake data;
data have;
input ID feature1 feature2 feature3;
cards;
1 7.72 5.43 4.35
1 5.54 2.25 8.22
1 4.43 6.75 2.22
1 3.22 3.21 7.31
2 6.72 2.86 6.11
2 5.89 4.25 5.25
2 3.43 7.30 8.21
2 1.22 3.55 6.55
;
run;
*Create summary data;
proc means data=have noprint;
by id;
var feature1-feature3;
output out=want median= var= mean= /autoname;
run;
*Show for display;
proc print data=want;
run;
*First done here:https://communities.sas.com/t5/General-SAS-Programming/Getting-creating-new-summary-variables-longitudinal-data/m-p/347940/highlight/false#M44842;
*Another way to present data is as follows;
proc means data=have stackods nway n min max mean median std p5 p95;
by id;
var feature1-feature3;
ods output summary=want2;
run;
*Show for display;
proc print data=want2;
run;
Though, PROC FREQ is more suited to what you want, not PROC MEANS.
This generates an output data set called WANT_FREQ. It should generate the percents as well.
proc freq data=sashelp.class;
table price_type /out=want_freq;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.