Help using Base SAS procedures

Outputting proportions into new variables

Reply
Learner
Posts: 1

Outputting proportions into new variables

I'm trying to create a new variable for my dataset that uses proportions from other variables.

I created a variable for the mean level of compliance in each room (room_complianceMEAN) in a separate dataset but cannot merge the sets back onto the main set and room_name. I'm using SAS 9.4

 

I’m trying to:

1. total the number of observations where a certain dispenser is used for a room

where dispensing_sensor_name = “sensor name” and room_name =“room name”;

2. create a variable that acts as the proportion of uses in that room to the total number of use in that room

3. add these variables to the dataset so they can be used along with others in a model

use_proportion, room_rank, worker_type, floor, intervention, etc.

 

PROC MEANS data = hh7;
VAR compliant;
CLASS room_name;
OUTPUT OUT=room_complianceMEAN MEAN= /AUTONAME;
run;

proc print data = room_complianceMEAN;
run;

PROC freq data = hh7;
where compliant =1;
tables dispensing_sensor_name;
by room_name;
OUTPUT OUT=room_USEPROPORTION;
run;
proc print data =room_USEPROPORTION;
run;

proc freq data = hh7;
where room_name="Room 7108-9";
tables dispensing_sensor_name*compliant /missing;
OUTPUT OUT=room_USEPROPORTION;
run;

Respected Advisor
Posts: 3,066

Re: Outputting proportions into new variables

Since you didn't explain, let me ask why do you say "cannot merge the sets back onto the main set and room_name"?

 

Explain!!!

 

Show us your SASLOG.

 

Show us a portion of your data, following these instructions: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller
Ask a Question
Discussion stats
  • 1 reply
  • 85 views
  • 0 likes
  • 2 in conversation