BookmarkSubscribeRSS Feed
SudheerAnkem
Calcite | Level 5

what is the result of the below statement, if CUR_VAL_DTE = "200160930"  and fixmmyy = 0129

 

beg_date = SUBSTR(&CUR_VAL_DTE,2,4)&fixmmyy;

6 REPLIES 6
Reeza
Super User

An error, it's invalid SAS code. 

SudheerAnkem
Calcite | Level 5

Why it is an invalid SAS code? text should not be attached with quates. I mean, "200160930" is a string and 2,4 takes the string starting for the 2nd character (i.e. 2) and a length of 4 bytes. so it could be 20016. Please correct me

RW9
Diamond | Level 26 RW9
Diamond | Level 26

beg_date = substr("200160930",2,4)0129;

                                                   ^

Here.  What I assume you want is to concatenate the substr() result with the 0129, so maybe:

beg_date = substr("200160930",2,4) || "0129";

or

beg_date = cats(substr("200160930",2,4),"0129");

 

Note however that your resulting string will look like this:

01600129

As the 2 means, start at character 2, and then read 4 characters from there, per the manual:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212264.htm

 

SudheerAnkem
Calcite | Level 5

Thank you and all others who responded to my query. Since, I don't have SAS compiler facility readily, I posted these queires. Please excuse me if it is an offence.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As per your other post some minutes back, the macro variable gets replaced with the text you specify, then that gets passed into the SAS compiler, which throws an error as @Reeza has mentioned.

beg_date = SUBSTR("200160930",2,4)0129;

 

I would suggest looking through the manual at each function you need explanation on.  Then with the code you have replace the

&<variable>

With the text you give.  Then check that it looks like valid SAS code.  Macro only generates text, Base SAS is the language.

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

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

 

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
  • 6 replies
  • 1216 views
  • 4 likes
  • 4 in conversation