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.
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;
stat, thanks but my date on sas data is of the format 40837, did you convert to ddmmyy first?
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;
Bet you imported something incorrectly. 40837 in SAS is 22 Oct 2071.
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.
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?
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.
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
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:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.