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

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
PeterClemmensen
Tourmaline | Level 20

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. 

 

PeterClemmensen_0-1659439739152.png

 

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. 

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
PeterClemmensen
Tourmaline | Level 20

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. 

 

PeterClemmensen_0-1659439739152.png

 

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. 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Discussion stats
  • 3 replies
  • 1313 views
  • 2 likes
  • 3 in conversation