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

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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