BookmarkSubscribeRSS Feed
Stephanie55901
Calcite | Level 5
Could anyone briefly explain what the !! does with the subst function?
8 REPLIES 8
Tim_SAS
Barite | Level 11
Do you mean substr instea of subst?

!! is the concatenation operator, so an expression of the form

charvar3 = charvar1 !! substr(charvar2, 1, 1);

concatenates the leftmost character from charvar2 to the right end of charvar1 to produce charvar3 (assuming charvar3 is long enough to hold the result of the concatenation).

See http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000780367.htm.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The key point made by Tim@SAS is that the charvar1 variable is not going to be trimmed of any trailing blanks -- if this behavior is undesired with your programming needs, you may want to consider also using either the CATT function (new with SAS 9) or using TRIM(charvar1) or possibly if you expect some particular length using the PUT(charvar1,) as well.

Scott Barry
SBBWorks, Inc.
Stephanie55901
Calcite | Level 5
thanks. I think i usually use the || for this. I am studying for the BASE certification exam, and there was a question on the practice exam , there was a question:

data hello;
phonenumber=3125551212;
code='(' !! substr(Phonenumber,1,3) !! ')';
run;

i totally understand what the substr function does, just stuck sometimes on what is trimmed

the answer is that code= ( 3)
data_null__
Jade | Level 19
You problems are caused by the data type, numeric, for PHONENUMBER and the conversion to character using BEST12. format.

How about a different method.

[pre]
9 proc format;
10 picture phone other=' 999)999-9999' (prefix='(');
NOTE: Format PHONE has been output.
11 run;

NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


12 data _null_;
13 phonenumber=3125551212;
14 *code='(' !! substr(Phonenumber,1,3) !! ')';
15 put (phone:) (=phone.);
16 run;

phonenumber=(312)555-1212
[/pre]
Stephanie55901
Calcite | Level 5
sorry that is 2 space before the 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
What is the answer? Not seeing the question but seeing the intended SAS code, it appears to me that someone is attempting to extract the area code an enclose it in parentheses to create SAS variable "code", right?

Scott Barry
SBBWorks, Inc.
Stephanie55901
Calcite | Level 5
the answer is ( 3) [2 spaces in front of the 3]
Stephanie55901
Calcite | Level 5
thanks, that helps alot to know that when SAS converts automatically to character, it converts to the best12. and right justifies, since the phone number is currently 10 digits, right justifying puts 2 trailing blanks in front and hence the 2 extra spaces.

makes sense!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1818 views
  • 0 likes
  • 4 in conversation