BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DDutton
Fluorite | Level 6

Hi Data Step Programmers,

I'm trying to do something which I thought could be solved with a simple function call, but I've searched and searched for a function to do this and have come up empty so far.

 

I have 3 numeric variables: year, month and day

I want to determine that they correspond to a valid date, without getting notes such as the below. I need something like MVALID or NVALID, but for a date, not a member name or variable name.  Surely this has been solved before!  Ideas?

 

I'm running SAS 9.4 M3, OS WX64_SV, .

 

62 data _null_;
63 year=2012;
64 month=2;
65 day=30;
66 date=mdy(month,day,year);
67 date2=input(put(year,4.)||put(month,z2.)||put(day,z2.),yymmdd8.);
68 put date=date7. date2=date7.;
69 run;

NOTE: Invalid argument to function MDY(2,30,2012) at line 66 column 7.
NOTE: Invalid argument to function INPUT at line 67 column 8.
date=. date2=.
year=2012 month=2 day=30 date=. date2=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 66:7 1 at 67:8

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Using the DATE2= variation, see if you can suppress messages by adding ?? in the right place:

 

date2=input(put(year,4.)||put(month,z2.)||put(day,z2.), ?? yymmdd8.);

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Using the DATE2= variation, see if you can suppress messages by adding ?? in the right place:

 

date2=input(put(year,4.)||put(month,z2.)||put(day,z2.), ?? yymmdd8.);
DDutton
Fluorite | Level 6

So embarrassed!  I forgot all about the ? and ?? modifiers! 

Thanks for the quick reminder!

dd

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 2 replies
  • 568 views
  • 0 likes
  • 2 in conversation