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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 707 views
  • 2 likes
  • 2 in conversation