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

Hi there,

 

Ich have following problem. I work with patient data and I have following variables: the year of observation (year), the entry date (entry, format yymmdd10.) and the exit date (exit, format yymmdd10.) into the insurance. There is a "." when there is no exit date. I only want to work with patients who were insured the whole year.

 

Therefore I would like to identify the patients that are not and put them in a separate file. For example observation year is 2014, but the entry date is after 2014-01-01. I tried following command:

 

data exclude; set all;
if year=2014 and (enty>2014-01-01 or (exit<2014-12-31 and exit ne .) then output exclude;
if year=2015 and (enty>2015-01-01 or (exit<2015-12-31 and exit ne .) then output exclude;
...and so on, for all available years

 

Does not work, I have the same amount of patients in my new file (exclude).

 

I tried to do it step by step by first "excluding" the patients with entry date after 20xx-01-01, then "excluding" patients with exid date before 20xx-12-31. Still the same amount of patients.

 

Maybe there is a problem with the format of the date and the command has to be written different? Or what else could be the problem?

 

Very happy for solutions. Thank you in advance,

Tamino

1 ACCEPTED SOLUTION
6 REPLIES 6
ballardw
Super User

Show us the LOG of your code. I suspect some warnings about value conversions

 

If your dates are actual SAS dates then you do not compare them to things like "2014-01-01". If the values are dates you compare to a standard value of "01JAN2014"d. There are so many ways of arranging numerals in nearly random ways that SAS only supports use of dates in Date9 (or similar) , in quotes with a following D to tell the compiler to treat the value as date. You may have to show us the results of PROC Contents to confirm the type of your variables.

 

Note: "Does not work" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

Tamino
Obsidian | Level 7

Thank you for your answer and sorry about the vague expression.

 

There are no warnings in the LOG, it just tells me that the new file has the same amount of patients as the source file (see attachement).

Note: BPMEDI.EXCL = exclude file, BPMEDI.BEST = all file

 

I think it is a problem with the format of the dates. The date is printed as "2014-01-01" but the variable is numeric as days counted up from 1960-01-01. So could the solution be to use the number of days in the command instead of the date?

Tamino
Obsidian | Level 7
Thank you very much!

With this command I got the file with the patients I wanted in it.
Kurt_Bremser
Super User

PS date literals must be supplied to the SAS interpreter in the form

'ddmonyyyy'd

where mon is the English three-letter abbreviation of the month, so 2022-01-01 is written as

'01JAN2022"d

The month can also be written in lowercase.

 

But in your code, the dates need to be dynamic, so no literals are necessary.

Kurt_Bremser
Super User

PPS 2014-01-01 is recognized by the SAS interpreter as a numeric formula, so you get the number 2014 minus 1 minus 1 = 2012, which is a day in the 1960s (1965-07-05).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1781 views
  • 2 likes
  • 3 in conversation