BookmarkSubscribeRSS Feed
souji
Obsidian | Level 7

 

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;

 

4 REPLIES 4
ed_sas_member
Meteorite | Level 14
Hi @souji
It seems to be fine 👍
souji
Obsidian | Level 7

Thank You to @ed_sas_member

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Reeza
Super User
What are you trying to do here? Get through a course or learn SAS. If it's the first, please continue as is. If you're actually trying to learn SAS, these questions are good but they will not teach you to be an effective SAS programmer at all.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 553 views
  • 2 likes
  • 4 in conversation