Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

DECODE for variables?

DECODE for variables?

DECODE for variables?


Can I use the DECODE function (or some similar function) for variables?

My basic problem is that I want to say:

if any of the variables &MONTH1, &MONTH2, &MONTH3, &MONTH4, &MONTH5, &MONTH6 equal '01' then set &SMONTH1, &SMONTH2, &SMONTH3, &SMONTH4, &SMONTH5, &SMONTH6 to 'January'

if the first variables equal '02' then set &SMONTH1, &SMONTH2, &SMONTH3, &SMONTH4, &SMONTH5, &SMONTH6 to 'February'


Of course &MONTH1, &MONTH2, &MONTH3, &MONTH4, &MONTH5, &MONTH6 are all different.

So my idea was to use something like DECODE. But I guess DECODE con only be used for data rows and not for variables?

Does anybody know how to do this?
Thanx a lot

RE: DECODE for variables?


I finally solved this problem. Here's the solution for anyone interested:

-SET &X = '0';
-SET &SMONTH.&X = IF &MONAT.&X EQ '01' THEN 'January'
-                  ELSE IF &MONTH.&X EQ '02' THEN 'February'
-                  ELSE IF &MONTH.&X EQ '03' THEN 'March'
-                  ELSE IF &MONTH.&X EQ '04' THEN 'April'
-                  ELSE IF &MONTH.&X EQ '05' THEN 'May'
-                  ELSE IF &MONTH.&X EQ '06' THEN 'June'
-                  ELSE IF &MONTH.&X EQ '07' THEN 'July'
-                  ELSE IF &MONTH.&X EQ '08' THEN 'August'
-                  ELSE IF &MONTH.&X EQ '09' THEN 'September'
-                  ELSE IF &MONTH.&X EQ '10' THEN 'October'
-                  ELSE IF &MONTH.&X EQ '11' THEN 'November'
-                  ELSE 'December';


RE: DECODE for variables?


You could use DECODE. Here's an example, based on what you did:

-REPEAT W1 FOR &X FROM 0 TO 5                        
-SET &SMONTH.&X = DECODE &MONTH.&X ('01' 'January'   
-                   '02'  'February'                 
-                   '03'  'March'                    
-                   '04'  'April'                    
-                   '05'  'May'                      
-                   '06'  'June'                     
-                   '07'  'July'                     
-                   '08'  'August'                   
-                   '09'  'September'                
-                   '10'  'October'                  
-                   '11'  'November'                 
-                  ELSE 'December');                 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close