BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DR_Majeti
Quartz | Level 8

String= 'abcdefghijklmnopqrstuvwxyz';

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

5 REPLIES 5
Quentin
Super User

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

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
data_null__
Jade | Level 19

Quentin wrote:

Um. why?

That's the same question I have.  There is a FORMAT that might be used.

data _null_;
   String=
'abcdefghijklmnopqrstuvwxyz';
  
put _all_;
   string=putc(string,
'REVERJ',length(string));
   put _all_;
  
run;

15         data _null_;
16            String= 'abcdefghijklmnopqrstuvwxyz';
17            put _all_;
18            string=putc(string,'REVERJ',length(string));
19            put _all_;
20            run;

String=abcdefghijklmnopqrstuvwxyz _ERROR_=
0 _N_=1
String=zyxwvutsrqponmlkjihgfedcba _ERROR_=
0 _N_=1
jwillis
Quartz | Level 8

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

Ksharp
Super User

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

DR_Majeti
Quartz | Level 8

Thank you all...

It is a task given to try...unable to get the dynamic code.

And working on how does PDV acts.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 3115 views
  • 8 likes
  • 5 in conversation