BookmarkSubscribeRSS Feed
Hdababs
Obsidian | Level 7

Greetings,

 

I need to exclude observations that include out of range dates. The column names I am trying to evaluate are identical but with a different prefix. In the code below, I am attempting to include the desired date range which supposed ignore date values  greater and less than 2022.

 

Regards

 

data reform; set adj_both;
Where "01JAN2022"d <= see_date1,see_date2,see_date3,see_date4,see_date5,......see_date310, <= "31DEC2022"d;
array fills(*) see_date1 - see_date&pdm_count.;
array filldayz(*) Dayz_Supply1 - Dayz_Supply&pdm_count.;
do i = 1 to (&pdm_count - 1) while (fills(i) ^= .);
if fills(i+1) < (fills(i) + filldayz(i)) then do;
fills(i+1) = (fills(i) + filldayz(i));
end;
end;
drop i;
run;

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@Hdababs wrote:

Greetings,

 

I need to exclude observations that include out of range dates. The column names I am trying to evaluate are identical but with a different prefix.


What does "identical but with a different prefix" mean? Show us examples. Or do you mean "identical but with a different SUFFIX"?

 

Where "01JAN2022"d <= see_date1,see_date2,see_date3,see_date4,see_date5,......see_date310, <= "31DEC2022"d;


As you probably know already, the above is not correct SAS syntax, even if you remove the dots ......

 

But its not even clear what you intend. Is your intention that if any ONE of these 310 variables is not in the year 2022, then the record is deleted? Or do they ALL have to be not in the year 2022 for the record to be deleted? Or something else?

 

Are these see_date variables numeric or character (according to PROC CONTENTS)? What are typical values of these variables?

--
Paige Miller
Hdababs
Obsidian | Level 7

Thank you. Identical column names: see_date1 see_date2 see_date3.... The prefix are the numbers following the column name. I am calling them prefix. My intention that if any ONE of these 310 variables is not in the year 2022, then the record is deleted. This is a sample of the output. Rows with red font must be deleted.

 

see_date1see_date2see_date3see_date4see_date5see_date6see_date7see_date8see_date9see_date10
22-Feb-2223-May-2221-Aug-2219-Nov-22......
15-Jan-2215-Feb-2217-Mar-2216-Apr-221-Sep-2230-Nov-2228-Feb-23...
18-Jan-2218-Apr-22........
18-Jan-2218-Apr-22........
18-Feb-2219-May-22........
3-Feb-224-May-22........
27-Feb-2229-Mar-2228-Apr-2228-May-2227-Jun-22.....
29-Mar-2217-May-2215-Aug-2215-Nov-2213-Feb-23.....
9-Feb-2214-Mar-2214-Apr-2214-Jul-2216-Oct-2214-Jan-23....
18-Mar-2221-Jun-2219-Sep-2219-Dec-2219-Mar-23.....
5-Apr-224-Jul-222-Oct-2231-Dec-2231-Mar-23.....
31-Mar-221-Jul-2229-Sep-2228-Dec-2228-Mar-23.....
PaigeMiller
Diamond | Level 26

@Hdababs wrote:

Thank you. Identical column names: see_date1 see_date2 see_date3.... The prefix are the numbers following the column name. I am calling them prefix. My intention that if any ONE of these 310 variables is not in the year 2022, then the record is deleted. This is a sample of the output. Rows with red font must be deleted.


Ok, thank you, this is a suffix, not a prefix.

 

So let's think about this ... if any ONE of these 310 variables is not in the year 2022 then we want to delete the record. Instead of using some brute force programming, we can summarize the dates in these variables by determining the maximum and minimum date. If the maximum or minimum is not in 2022, we would delete the record.

 

So

 

data want;
    set have;
    if min(of see_date:)<'01JAN2022'd or ... 
         then delete;
run;

 

I have left part of the code as ... because it is your homework assignment to fill in that part.

 

Also, the above code will only work if the variables are numeric, and represent actual SAS date values (which are the integer number of days since 01JAN1960). If the variables contain any other representation of the dates, this will not work. I did ask in my earlier post if these values were numeric or character, I don't see an answer.

--
Paige Miller
Hdababs
Obsidian | Level 7

Thank you. I will report back how it goes.

ballardw
Super User

I might use, just to make it clear that the intended logic was based on Year, so when I see the code 9 months later I have a chance of remembering that was the stated limit.  The specific date is more flexible in general though.

data want;
    set have;
    if year(min(of see_date:) )< 2022 or ... 
         then delete;
run;

 

 

Hdababs
Obsidian | Level 7

Greetings,

I was able to figure out the issue. There was a macro variable retrieving previous year value. The reporting period is 2022 and the previous year is 2021. Since I am running the code in 2023, I have to indicate that the previous reporting year is 2021.

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!

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
  • 6 replies
  • 650 views
  • 0 likes
  • 3 in conversation