BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

WARNING: INPUT function reported 'WARNING: Illegal first argument to function' while processing WHERE
clause.

 

I want to convert a year to numeric and subset data:

 

data want;

set have;

where input(SUBSTR(trim(Primary_Completion_Date),LENGTH(TRIM(Primary_Completion_Date))-3),best.) >=2015;

run;

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post test data in the form of a datastep!!

 

It takes away the whole guessing part.  What does primary_completion_date look like, is it numeric or character?  If its numeric you don't need any of that:

where year(primary_completion_date) >= 2015;

If its character convert to numeric first:

where year(input(primary_completion_date,yymmdd10.)) >= 2015;
SASPhile
Quartz | Level 8

the date is charatcter string and I'm getting the year from that string "02/08/2015"

RW9
Diamond | Level 26 RW9
Diamond | Level 26

So:

where year(input(primary_completion_date,ddmmyy10.)) >= 2015;
Kurt_Bremser
Super User

If your date is as you posted, your code has to work:

data test;
primary_completion_date = "02/08/2015";
x1 = input(SUBSTR(trim(Primary_Completion_Date),LENGTH(TRIM(Primary_Completion_Date))-3),best.);
run;

Log from that:

27         data test;
28         primary_completion_date = "02/08/2015";
29         x1 = input(SUBSTR(trim(Primary_Completion_Date),LENGTH(TRIM(Primary_Completion_Date))-3),best.);
30         run;

NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

As you can see, no WARNING.

So I guess your primary_completion_date is not really what you posted. Could it be that it is already a SAS date (numeric with date format)?

Maxim 3: Know your data.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 2449 views
  • 3 likes
  • 3 in conversation