Hi,
I am trying to test if the mean of two variables differ within two specific periods.
Precisely, I want to test if the mean of RSP differs in the period: 25Jan2002 through 24Feb2003, compared to the period: 25Feb2003 through 26Mar2004.
I tried to create a 'flag' variable to distinguish both time periods. However, my log files suggests that the 'CLASS variable does not have two levels'. I am not too sure why the class flag variable does not have two levels as I have enough observations within the specified periods.
See my codes:
data xx;
set x;
Startdate = '25Jan2002'd < '24Feb2003'd < '24Feb2003'd;
Enddate = '25Feb2003'd < '24Feb2003'd < '26Mar2004'd;
If Startdate <= '24Feb2003'd <= Enddate then flag=1;
else flag = 0;
run;
proc ttest data=xx;
class flag;
var RSP;
run;
run;
Log File:
data xx;
set x;
Startdate = '25Jan2002'd < '24Feb2003'd < '24Feb2003'd;
Enddate = '24Feb2003'd < '24Feb2003'd < '26Mar2004'd;
If Startdate <= '24Feb2003'd <= Enddate then flag=1;
else flag = 0;
run;
NOTE: There were 6179 observations read from the data set WORK.SPVIXTWO.
NOTE: The data set WORK.SPVIXTWOX has 6179 observations and 34 variables.
proc ttest data=xx;
class flag;
var VarRSP20;
run;
ERROR: The CLASS variable does not have two levels.
Is there an alternative way to do this or are my codes wrong? I would be glad to provide clarifications where necessary.
Thank you in anticipation!
You need to use your date variable to determine the flags, but you haven't done that.
For example if the variable that contains the date in data set x is named DATE, then
If '25jan2002'd<date<'24feb2003'd then flag=1;
You need to use your date variable to determine the flags, but you haven't done that.
For example if the variable that contains the date in data set x is named DATE, then
If '25jan2002'd<date<'24feb2003'd then flag=1;
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.