Help using Base SAS procedures

SAS date variables function

Reply
Contributor
Posts: 36

SAS date variables function

Hi I have a dataset with dates,

the date 07/04/2014 is represented on my sas spreadsheet  as 40837.

Now I want to create a variable like this.

Id date of manufacture         expired?

111                             40837                            

I want  an extra column that tells me if manufacture date is suitable

eg if after 28/04/2014 then  then date of manufacture is okay, like below

Id date of manufacture         suitable?

111                             40837                           yes

I know  I  can use IF function but don’t know how to use with dates.

Trusted Advisor
Posts: 1,228

Re: SAS date variables function

Something like this?

data have;
input id dom :ddmmyy10. expired :ddmmyy10.;
if dom<expired then suitable='yes';
else suitable='no';
datalines;
111     07/04/2014  28/04/2014
;

proc print data=have;
run;

Contributor
Posts: 36

Re: SAS date variables function

stat, thanks but my date on sas data is of the format 40837, did you convert to  ddmmyy first?

Trusted Advisor
Posts: 1,228

Re: SAS date variables function

May be this is what you need.

data have;
input Id dom  expired :ddmmyy10.;
format dom expired ddmmyy10.;
if dom<expired then suitable='yes';
else suitable='no';
datalines;
111     40837  28/04/2014
;

proc print data=have;
run;

Super User
Posts: 11,343

Re: SAS date variables function

Bet you imported something incorrectly. 40837 in SAS is 22 Oct 2071.

Super User
Posts: 19,789

Re: SAS date variables function

Assuming you haven't imported something incorrectly, a SAS date is a number.

You can apply a format so that it appears as a date, but the calculations will be correct.

http://www.lexjansen.com/pharmasug/2005/tutorials/tu01.pdf

Contributor
Posts: 36

Re: SAS date variables function

My date is showing corectly as 4 April 2014 so to create a table with an expired flag but without creating another column with that cufoff date displayed on all my columns per your example,  can I put something like this

Data want

Set table

Length date of manufacture $25

If   date of manufacture is greater than 28 April 2014 then 'expired'

Run

Will sas recognise 4 April 2014 date, without express ing in a different form?

Super User
Super User
Posts: 7,954

Re: SAS date variables function

Sorry, just to clarify, what is a  "sas spreadsheet"  and what is the 40837?  Do you meant that you have an Excel spreadsheet which has dates in, then when you proc import that spreadsheet you get a dataset which has columns with the number in rather than a date?  If the numer represents a date then yes, your if should be ok like:

if date_of_manufacture > '28APR2014'd then Result="Expired";

Note the quotes around the date text and the d.  You wouldn't be able to use the text 28 April 2014 directly, you need to process it.  Perhaps start by showing some text data and what you want out at the end.

Contributor
Posts: 36

Re: SAS date variables function

RW9

Ok specifically, this is how my imported data, lets call it work. tablea looks like

id        date

111   12/04/2014

123     26/04/2014

I want to return a table that looks like this, i.e if date is after 20/04/2014 the item has expired if the date is before that then the item has not expired. Results  should be shown as follows:

id          date                     Expired?

111      12/04/2014             no

123       24/04/2014             yes

Thanks

Super User
Posts: 19,789

Re: SAS date variables function

Substitute in your variable names into @RW9 code.

if date> '20APR2014'd then Expired="Yes";

else Expired="No";


The first level SAS programming course is available free online here:

Programming 1


Ask a Question
Discussion stats
  • 9 replies
  • 356 views
  • 0 likes
  • 5 in conversation