BookmarkSubscribeRSS Feed
Rsadiq
Calcite | Level 5

Hello how would this column resp_yr be turned into a character value so that this substr can work?

 

Thank you

 

Rida

 

 

 

NOTE: %INCLUDE (level 1) ending.
394       
395        PROC SQL;
396         CREATE TABLE rptlib.sum_responses_curryr AS
397         SELECT *
398         FROM outlib.sum_responses_all_yrly
399         WHERE SUBSTR(resp_yr,1,4) = '&begyr.'
400        ;
ERROR: Function SUBSTR requires a character expression as argument 1.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
400      !  QUIT;

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is a very basic topic, converting number to character and vice versa.  The put and input functions are respectively used:

where substr(put(RESP_YR,best.),1,4)='&begyr.'

Note the put() which puts the numeric resp_yr into the best. format.

Tom
Super User Tom
Super User

So RESP_YR is a number.

Assuming it is the YEAR (ie 2010 or 2017 for example).

Assuming that BEG_YR also a four digit string that looks like a year.

 

 

 

WHERE resp_yr = &begyr

Example.

data have;
  input resp_yr @@ ;
cards ;
2010 2013 2014 2015 
;
%let begyr=2013;

data want ;
 set have ;
 where resp_yr = &begyr ;
run;
ballardw
Super User

@Rsadiq wrote:

Hello how would this column resp_yr be turned into a character value so that this substr can work?

 

Thank you

 

Rida

 

 

 

NOTE: %INCLUDE (level 1) ending.
394       
395        PROC SQL;
396         CREATE TABLE rptlib.sum_responses_curryr AS
397         SELECT *
398         FROM outlib.sum_responses_all_yrly
399         WHERE SUBSTR(resp_yr,1,4) = '&begyr.'
400        ;
ERROR: Function SUBSTR requires a character expression as argument 1.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
400      !  QUIT;


Also note that = '&begyr.' will not likely get what you want any way as with single quotes the value compared would be &begyr NOT the resolved value of the macro variable begyr. Use = "&begyr."   

 

And what kind of values does the variable resp_yr take anyway? If they are numeric actual years (2017)

then

where resp_yr = &begyr. should work just fine.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1780 views
  • 0 likes
  • 4 in conversation