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

Hello Everyone,

I am trying to run a chi-square analysis on data pre vs. post an event. For example the event happened on the first day of April  2014 and I have data for the months Jan 14, Feb 14, Mar 14 ,April 13, and May 13 prior to the event occurring. I would like to include all the data prior to the event and all data post the event and compare them.

I would like to do something like this:

IF MONTH = 'April'         AND Year = 2013 THEN  EVENT  = 'PRIOR';

IF MONTH = 'May'         AND Year = 2013 THEN  EVENT = 'PRIOR';

IF MONTH = 'January'   AND Year = 2014 THEN EVENT  = 'PRIOR';

IF MONTH = 'February' AND Year = 2014 THEN EVENT  = 'PRIOR';

IF MONTH = 'March'      AND Year =2014  THEN EVENT  = 'PRIOR';

IF MONTH = 'April'   AND Year = 2014    THEN  EVENT  = 'AFTER';

IF MONTH = 'May'   AND Year = 2014     THEN  EVENT = 'AFTER';

IF MONTH = 'June'  AND Year = 2014     THEN EVENT  = 'AFTER';

I know AND statements do not exist in this sense. Is there a better way to approach this? I plan on running a proc freq for a chi-square analysis afterwards.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What sense to you mean by "AND statements do not exist in this sense"? That is basically perfectly good data step code.

Could be more efficient as

if (month in ('April','May') and year=2013) or (month in ('January','February','March') and year = 2014) then event = 'PRIOR';

Else if month in ('April', 'May','June') and year=2014 then event = 'AFTER';

View solution in original post

3 REPLIES 3
ballardw
Super User

What sense to you mean by "AND statements do not exist in this sense"? That is basically perfectly good data step code.

Could be more efficient as

if (month in ('April','May') and year=2013) or (month in ('January','February','March') and year = 2014) then event = 'PRIOR';

Else if month in ('April', 'May','June') and year=2014 then event = 'AFTER';

art297
Opal | Level 21

Like said, your code would work but would work more quickly using if then else. However, you can do the same thing with even less code using something like:

data have;

  input month $ year;

  if input(cat(month,' 1,',year),anydtdte21.) ge '01apr2014'd then event='AFTER';

  else event='PRIOR';

  cards;

April 2013

May 2013

January 2014

February 2014

March 2014

April 2014

May 2014

June 2014

;

daszlosek
Quartz | Level 8

Hello ballardw,

My apologies, this was more or less a lack of knowledge of SAS on my part and not being able to find an example use 'and' in an if/then statement. Plus my statement were not working correctly, but now they are.

Thank all of you for your help!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 738 views
  • 3 likes
  • 3 in conversation