turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Date Conversion

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-10-2013 12:44 PM

I have a question about date conversions. I have a proc sql code where I need to take a the dates of the year and assign a number to it

I can do a case statement and say

case fst_srvc_dt = '1/1/2011' then 0 end as date

case fst_srvc-dt = '1/2/2011' then 1 end as date1

and so on. What I need is each date to equal a day so when I get to 12/31/2011 it is 365. I know my case statement is not 100% right and know how to build them just doing this quick and dirty type thing. There has to be an easier way to do this. Maybe something that says if my date is between 1/1/2011 and 12/31/2011 start with 1/1/2011 =0 and add +1 as it goes to 12/31/2011.

This is needed because we have 100's of patients with various dates of service in this time period and we want the patient ot be assigned a number for the date of service rather than the actual date. So I might end up with 50 patients that had a date of service that was 3/31/2011, then all those 50 patients would be assigned 90 as the number.

THanks

Accepted Solutions

Solution

05-10-2013
01:04 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-10-2013 01:04 PM

Like Paige said, the intck function will work, as will the datdif function. The latter might be easier if you want to alter the day count based on standardizing the number of days to, say, 360, 365 or the actual number of days in the year. e.g.:

data have;

format fst_srvc_dt date9.;

do fst_srvc_dt=18628 to 18628+364;

id+1;

output;

end;

run;

proc sql;

create table want as

select id, datdif(mdy(1,1,year(fst_srvc_dt)), fst_srvc_dt, 'act/act') as date

from have

;

quit;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-10-2013 12:48 PM

The INTCK function does exactly what you need

Solution

05-10-2013
01:04 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-10-2013 01:04 PM

Like Paige said, the intck function will work, as will the datdif function. The latter might be easier if you want to alter the day count based on standardizing the number of days to, say, 360, 365 or the actual number of days in the year. e.g.:

data have;

format fst_srvc_dt date9.;

do fst_srvc_dt=18628 to 18628+364;

id+1;

output;

end;

run;

proc sql;

create table want as

select id, datdif(mdy(1,1,year(fst_srvc_dt)), fst_srvc_dt, 'act/act') as date

from have

;

quit;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-10-2013 01:06 PM

I don't think you need a case statement. I'd read the character field fst_srvc_dt in as a SAS date, convert it to a Julian date, extract the day segment and subtract 1:

put(substr(put(input(fst_srvc_dt, anydtdte10.), julian5.), 3), 3.) - 1 as date

Note that the highest value will be 364 for 2011 and that you will get just one date variable. If you want 365 of them, I'd use PROC TRANSPOSE to transpose the data.