String= 'abcdefghijklmnopqrstuvwxyz';
Um. why?
15 data _null_; 16 String='abcd'; 17 length Reverse $4; 18 do i=1 to length(String); 19 substr(Reverse,i,1)=substr(String,length(String)+1-i,1); 20 end; 21 put (String Reverse)(=); 22 run; String=abcd Reverse=dcba
Um. why?
15 data _null_; 16 String='abcd'; 17 length Reverse $4; 18 do i=1 to length(String); 19 substr(Reverse,i,1)=substr(String,length(String)+1-i,1); 20 end; 21 put (String Reverse)(=); 22 run; String=abcd Reverse=dcba
Quentin wrote:
Um. why?
That's the same question I have. There is a FORMAT that might be used.
This can be refined, but this works without using the Reverse function.
data _null_;
String= 'abcdefghijklmnopqrstuvwxyz';
stringlen = length(string);
length reversestring $ 26; /* ideally this would be set to be the same length of stringlen */
length onevalue $ 1;
do i=1 to stringlen;
if i=1 then do;
reversestring = substr(string,stringlen,1);
end;
else do;
if i ne stringlen then do;
position = stringlen - i;
onevalue = substr(string,position,1);
reversestring = cats(reversestring,onevalue);
end;
end;
end;
put reversestring=;
run;
reversestring=zxwvutsrqponmlkjihgfedcba
It looks like a homework.
data _null_; String='abcd'; length Reverse $4; do i=length(String) to 1 by -1; reverse=cats(reverse,char(string,i)); end; put (String Reverse)(=); run;
Xia Keshan
Thank you all...
It is a task given to try...unable to get the dynamic code.
And working on how does PDV acts.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.