Please correct me if I wrong coded in the below:
/*Scenario:
1. Subset the data into two data sets, work.young and work.mid based on Age variable.
2. work.young should contain observations with Age less than 40 years old.
3. work.mid should contain observations with Age between 40 and 65 years old, inclusively.
4. How many observations are in the mid data set?
5. What is the CustomerId for observation 14 in the young data set?
6. What is the average Age of the customer in the young data set? */
data work.young work.mid;
set Souj.Input41;
if Age<40 then output work.young;
else if 40<= Age <=65 then output work.mid;
run;
proc means data=work.young;/*I think,#6*/
var Age;
run;
Thank You to @ed_sas_member
As I discussed earlier, there is no need to split the data into two data sets to do these analyses. If some instructor is requesting that you do this, they are teaching you a rather weak and ineffective technique in SAS. This can all be done without creating one or two new datasets using PROC MEANS. While this may not make the slightest difference in a small problem, it could make a difference using huge real world data sets, and splitting data sets up like this is also not a good way to program.
proc format;
value agef. low-<40='0-40' 40-65='40-65';
run;
proc means data=souj.input41;
var age;
format age agef.;
run;
or #6 can be programmed like this:
proc means data=souj.input41(where=(40<=age<=65));
var Age;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: