BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

Hi...I am getting an error message and the reason is that there has been a change to some of the variables. I would like to include a case statement to check to see if the StartDate and EndDate are of numeric expression or character in the conversion of the dates. Any suggestion on the best way to handle this situation. Thanks

 

721 proc sql noprint;
1722 create table ESDatesList as
1723 select distinct
1724 SROffer.Department,
1725 SROffer.Course,
1726 SROffer.CourseType,
1727 SROffer.Section,
1728 SROffer.CourseName,
1729 put(datepart(SROffer.StartDate),yymmdd10.) as StartDate,
1730 put(datepart(SROffer.EndDate),yymmdd10.) as EndDate,
1731 SROffer.TextTerm,
1732 SROffer.SemesterID,
1733 SROffer.AccessCampusID,
1734 SROffer.AccessCampus,
1735 SROffer.ProgramCampus
1736 from work.SROffer
1737 where SROffer.Department = 'ES';
ERROR: Function DATEPART requires a numeric expression as argument 1.
ERROR: Numeric format YYMMDD in PUT function requires a numeric argument.
ERROR: Function DATEPART requires a numeric expression as argument 1.
ERROR: Numeric format YYMMDD in PUT function requires a numeric argument.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
1738 quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

Hi,

you won't be able to perform this in one step with proc sql.

The vtype function will return the type of a variable in a data step or you can use the sashelp.vcolumn table in a data _NULL_ step to dynamically call execute the proc sql you need.

________________________

- Cheers -

View solution in original post

3 REPLIES 3
Oligolas
Barite | Level 11

Hi,

you won't be able to perform this in one step with proc sql.

The vtype function will return the type of a variable in a data step or you can use the sashelp.vcolumn table in a data _NULL_ step to dynamically call execute the proc sql you need.

________________________

- Cheers -

twildone
Pyrite | Level 9

Hi....I did try the vtype function but got the error message that it is not supported in proc sql. I thought there may be a equivalent function for proc sql.

ballardw
Super User

@twildone wrote:

Hi...I am getting an error message and the reason is that there has been a change to some of the variables.


Why did the variables change? Where? Who decided on this change?

 

What exactly do you mean by "handle this situation"?   Does that mean fix the change of the variable type? Or what?

 

And just what are you going to accomplish with a character variable that happens to look like a date in later processing?

 

You would have to check BEFORE the sql step, I think.

If you are contemplating conditional execution of as code inside a single SQL call then I suspect you will have an issue as the compiler/syntax checker is still going to complain.

 

You don't even show use what actual values for Startdate look like.

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
  • 3 replies
  • 668 views
  • 0 likes
  • 3 in conversation