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
Create the dates with the MDY function:
if enty > mdy(1,1,year) or (exit ne . and exit < mdy(12,31,year)) then output exclude;
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.
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?
Create the dates with the MDY function:
if enty > mdy(1,1,year) or (exit ne . and exit < mdy(12,31,year)) then output exclude;
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.
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).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.