BookmarkSubscribeRSS Feed
zetter
Calcite | Level 5

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.

9 REPLIES 9
stat_sas
Ammonite | Level 13

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;

zetter
Calcite | Level 5

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

stat_sas
Ammonite | Level 13

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;

ballardw
Super User

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

Reeza
Super User

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

zetter
Calcite | Level 5

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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

zetter
Calcite | Level 5

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

Reeza
Super User

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


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1084 views
  • 0 likes
  • 5 in conversation