Obsidian | Level 7

## A function on the LEFT side of the eq-sign?!

Can anyone explain - why is this possible? Is it just a smart way to add an extra character to the string?

Nevet seen it before. Topic for next SAS Programming?

do i=1 to num_ids;
do j=1 to 30;
temp=ceil((num_allowed * rand("uniform")));
substr(my_id30,j,1)=substr(allowed,temp,1);
put temp my_id30;
end;
output;
call symputx('_pwd30', my_id30);
end;

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

## Re: A function on the LEFT side of the eq-sign?!

I assume the question relates to using a function to the left of the equal sign and not the posted code.

Yes, the Substr Function can be used to the left of the equal sign. Technically the Substr Function (left of = ) and Substr Function (right of = ) are two different functions with two different documentations (see below). As far as I know, this is the only function where this is the case.

I assume that SAS created this capability because it seems logic to many developers and aligns well with other languages. However, in most cases, its functionality can easily be obtained by other character functions.

Regards Peter.

3 REPLIES 3
Diamond | Level 26

## Re: A function on the LEFT side of the eq-sign?!

Why is it possible? Because the smart people at SAS allowed this to happen in the case of the SUBSTR function.

See the documentation here: https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p0uev77ebdwy90n1rsd7hwjd2qc3.htm

I don't think it is adding a character to the string; it is replacing the character in the j-th position in the text string of variable MY_ID.

In the future, please don't show us partial DATA step code, show us the ENTIRE data step code.

--
Paige Miller
Tourmaline | Level 20

## Re: A function on the LEFT side of the eq-sign?!

I assume the question relates to using a function to the left of the equal sign and not the posted code.

Yes, the Substr Function can be used to the left of the equal sign. Technically the Substr Function (left of = ) and Substr Function (right of = ) are two different functions with two different documentations (see below). As far as I know, this is the only function where this is the case.

I assume that SAS created this capability because it seems logic to many developers and aligns well with other languages. However, in most cases, its functionality can easily be obtained by other character functions.

Regards Peter.

Obsidian | Level 7

## Re: A function on the LEFT side of the eq-sign?!

R T F M
Discussion stats
• 3 replies
• 610 views
• 2 likes
• 3 in conversation