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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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