Help using Base SAS procedures

If statement error

Reply
Contributor
Posts: 21

If statement error

[ Edited ]

Hello all,

Please help with the issue here. I have a list of IDs with their eligibility from and thru date.

 

For instance:

ID From Thru:

1  01/01/2012  01/01/2016

2  01/01/2015  12/31/2015

3  01/01/2014  07/01/2015

4  03/01/2012  09/01/2016

 

I would like my results to look like:

ID From Thru:

1  01/01/2015  12/31/2015

2  01/01/2015  12/31/2015

3  01/01/2015  07/01/2015

4  01/01/2015  12/31/2015

 

I used the if statement below and produce blank from and thru results that looks similar to:

ID From Thru:

1  .  .

2  01/01/2015  12/31/2015

3 .  07/01/2015

4  .  .

 

Can anyone help me with this issue? Thank you!!

 

if year(from) < &current_year. then from = &service_start_date_dateform.;
if year(thru) > &current_year. then thru = &service_end_date_dateform.;

Super User
Posts: 10,550

Re: If statement error

Please show the values of your macro variable &current_year, &service_start_date_dateform and &service_end_date_dateform. Also are your From and Thru variables SAS date values or Character values that look like dates?

Contributor
Posts: 21

Re: If statement error

Hello,

The macro is attaced here:

%let service_start_date_dateform = '01JAN2015';
%let service_end_date_dateform = '31DEC2015';

%let current_year = 2015;

 

Both the from and thru are in the date format with length=8

 

I have tried where statement or "if, else if"; both wont work. 

Super User
Posts: 5,260

Re: If statement error

Since you are referring to an error, it would be nice to see the log.

First, you need the dates to be stored as SAS dates.

If you are using macro variable as constants, I think the easiest is to have them formatted as DATE9, so you can use them in the assignment as:

"&service_start_date_dateform."D

 

Data never sleeps
Contributor
Posts: 21

Re: If statement error

Thank you very much! Adding "d" at the end of the macro works!! 

Ask a Question
Discussion stats
  • 4 replies
  • 325 views
  • 0 likes
  • 3 in conversation