BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MrT13
Fluorite | Level 6

Hi,

 

I'm trying to solve the following exercise, but I haven't got a clue how to solve letter c.

Can someone help me out? 

34. A local gym runs a New Year’s membership offer that is available to anyone who joins the gym on
January 1st. The promotion states that if the new member continues to work out for at least 30
minutes a day for the first four months of the year, then they will have the $150 start-up fee
refunded. This year, 245 people signed up for the offer. Members were tracked automatically via
the computer check-in system when they arrived and left the gym. The raw data file NewYears.dat
contains variables for the member ID, and check-in times for the first 119 days of the year,
followed by the check-out times for the first 119 days of the year.
a. Examine the raw data file NewYears.dat and read it into SAS.
b. Create new variables for the time (in minutes) that the member spent at the gym each day.
c. Create a flag that identifies whether members are eligible for the refund. Members are eligible if
they worked out for at least 30 minutes a day for all 119 days.
d. Calculate the overall average time spent at the gym for each new member.
e. View the resulting data set. In a comment in your program, state the values for refund eligibility
and overall average time for members 330 and 331.*/
proc import
datafile="/folders/myfolders/The Little SAS Book/Input/Chapter 3/NewYears.dat"
out=newy replace dbms=dlm;
delimiter=",";
getnames=yes;
run;

data newy;
set newy;
array in {119} In_Day_1-In_Day_119;
array out {119} Out_Day_1-Out_Day_119;
array timesession {119};

do i=1 to 119;
timesession{i}=out{i} - in{i};
end;
AvgTime=mean(of timesession1-timesession119);
informat In_Day_1-In_Day_119 Out_Day_1-Out_Day_119 AvgTime
timesession1-timesession119 time5.;
format In_Day_1-In_Day_119 Out_Day_1-Out_Day_119 AvgTime
timesession1-timesession119 time5.;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

c. Create a flag that identifies whether members are eligible for the refund. Members are eligible if
they worked out for at least 30 minutes a day for all 119 days.

 

That would be if the MINIMUM value for ALL of the variables is 30 minutes or more AND all of the values are not missing.

 

Which would look a lot like your AvgTime but with the MIN function instead of MEAN and "ge 30" if the values in the Timesession variables are minutes.

 

Flag = (min(of timesession1-timesession119) ge 30 AND nmiss(of timesession1-timesession119)=0 );

 

The missing needs to be considered because the MIN function will ignore missing values for returning the minimum.

 

SAS will return 1 for true and 0 for false for

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Please attach the data file to your post, so we can run your import code and have the dataset for testing.

In case the communities website rejects the .dat extension, change it to .csv.

ballardw
Super User

c. Create a flag that identifies whether members are eligible for the refund. Members are eligible if
they worked out for at least 30 minutes a day for all 119 days.

 

That would be if the MINIMUM value for ALL of the variables is 30 minutes or more AND all of the values are not missing.

 

Which would look a lot like your AvgTime but with the MIN function instead of MEAN and "ge 30" if the values in the Timesession variables are minutes.

 

Flag = (min(of timesession1-timesession119) ge 30 AND nmiss(of timesession1-timesession119)=0 );

 

The missing needs to be considered because the MIN function will ignore missing values for returning the minimum.

 

SAS will return 1 for true and 0 for false for

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 527 views
  • 2 likes
  • 3 in conversation