IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SAS Requirement - remove the trailing ‘{‘ from a variabl


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
venktv

New User


Joined: 29 Mar 2006
Posts: 59
Location: Montreal

PostPosted: Mon Sep 08, 2008 1:58 pm
Reply with quote

Hi Friends,

The requirement is to remove the trailing ‘{‘ from a variable using SAS code.

For eg.:

If Var1 is ‘ABC}}}}}}}}}’ then only ‘ABC’ should be retained
If Var1 is ‘ABC}}}}}}}XYX’ then ‘ABC}}}}}}}XYX’ should be the output
If Var1 is ‘ABC}}}}}}}XYX}}}}}}}}}’ then ‘ABC}}}}}}}XYX’ should be the output
If Var1 is ‘}}}}}}}}}}’ then the output should be null


Can you pls help me to write a logic in SAS language

Thanks
Back to top
View user's profile Send private message
Kevin Wailes

New User


Joined: 29 Aug 2008
Posts: 10
Location: UK

PostPosted: Mon Sep 08, 2008 4:20 pm
Reply with quote

Try something like :-

x = INDEX(var1,'{');
x = x - 1;
var2 = SUBSTR(var1,1,x);
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Mon Sep 08, 2008 4:31 pm
Reply with quote

fuzzy logic....

the OP asks for a SAS solution to remove a trailing "{"

... in a cobol forum

... the sample strings contain only "}"

... gets a rexx solution...


12.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon Sep 08, 2008 4:44 pm
Reply with quote

Quote:

fuzzy logic....
the OP asks for a SAS solution to remove a trailing "{"
... in a cobol forum
... the sample strings contain only "}"
... gets a rexx solution...

Aaaaaaaah Enrico, it must be Monday.

Problem is accepting the internal possibilities, but try this UNTESTED code
Code:

DATA OUT01;                                     
  INFILE    WORKIN;                             
  INPUT     VAR01       $CHAR44.;               
  VAR01 = TRIM(VAR01);                         
  A = 1;                                       
  DO WHILE (A = 1);                             
    LASTCHAR = SUBSTR(VAR01,LENGTH(VAR01),1);   
     IF LASTCHAR NE '}'                         
      THEN A = 0;                               
    ELSE DO;                                   
      IF VAR01 = '}' THEN DO;                   
        A = 0;                                 
        VAR01 = ' ';                           
      END;                                     
      ELSE                                     
        VAR01 = SUBSTR(VAR01,1,LENGTH(VAR01)-1);
    END;                                       
  END;                                         
Back to top
View user's profile Send private message
venktv

New User


Joined: 29 Mar 2006
Posts: 59
Location: Montreal

PostPosted: Mon Sep 08, 2008 4:52 pm
Reply with quote

Hi enrico,

Where is the SAS forum?... there is separate forum for SAS.. so posted here.... icon_smile.gif anyway ... thanks for the suggestion... but i want it in SAS not in REXX..
Back to top
View user's profile Send private message
venktv

New User


Joined: 29 Mar 2006
Posts: 59
Location: Montreal

PostPosted: Mon Sep 08, 2008 5:26 pm
Reply with quote

Hi Expat,

Thanks very much for the logic.. its working icon_smile.gif

Thank you....
Back to top
View user's profile Send private message
Kevin Wailes

New User


Joined: 29 Aug 2008
Posts: 10
Location: UK

PostPosted: Mon Sep 08, 2008 5:58 pm
Reply with quote

Actually not REXX but using SAS functions
Back to top
View user's profile Send private message
Kevin Wailes

New User


Joined: 29 Aug 2008
Posts: 10
Location: UK

PostPosted: Mon Sep 08, 2008 6:05 pm
Reply with quote

And to prove the point :-

1 DATA;
2 VAR1 = 'ABCDEF}}}}}';
3 X = INDEX(VAR1,'}');
4 X = X - 1;
5 VAR2 = SUBSTR(VAR1,1,X);
6 RUN;

NOTE: THE DATA SET WORK.DATA1 HAS 1 OBSERVATIONS AND 3 VARIABLES.
NOTE: COMPRESSING DATA SET WORK.DATA1 INCREASED SIZE BY 100.00 PERCENT.
COMPRESSED IS 2 PAGES; UN-COMPRESSED WOULD REQUIRE 1 PAGES.
2 THE SAS SYSTEM

NOTE: THE DATA STATEMENT USED 0.00 CPU SECONDS AND 10463K.

6 !
7 PROC PRINT;
8 RUN;

NOTE: THERE WERE 1 OBSERVATIONS READ FROM THE DATA SET WORK.DATA1.
NOTE: THE PROCEDURE PRINT PRINTED PAGE 1.
NOTE: THE PROCEDURE PRINT USED 0.01 CPU SECONDS AND 11311K.

8 !

THE SAS SYSTEM

OBS VAR1 X VAR2

1 ABCDEF}}}}} 6 ABCDEF
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon Sep 08, 2008 6:39 pm
Reply with quote

Quote:
If Var1 is ‘ABC}}}}}}}XYX}}}}}}}}}’ then ‘ABC}}}}}}}XYX’ should be the output


Unfortunately the INDEX function will return the first occurance and from the OP's original post, quote above, the method shown in your last post would not give the correct result.

Result would be ABC
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 08, 2008 6:42 pm
Reply with quote

Code:
var1rev = reverse(var1) ;
do while (substr(var1rev,1,1) = '}');
   var1rev = substr(var1rev, 2) ;
end;
var1 = reverse(var1rev);
Back to top
View user's profile Send private message
Kevin Wailes

New User


Joined: 29 Aug 2008
Posts: 10
Location: UK

PostPosted: Mon Sep 08, 2008 7:39 pm
Reply with quote

Didn't spot that case in the original requirement. Should have.

Code:
DATA;                                                       
VAR1 = 'ABCDEF}}}}}}}}}GHI';                                   
L = LENGTH(VAR1);                                           
DO I=LENGTH(VAR1) TO 1 BY -1 WHILE (SUBSTR(VAR1,I,1) = '}');
  L = L - 1;                                                 
END;                                                         
VAR2 = SUBSTR(VAR1,1,L);                                     
RUN;                                                         
PROC PRINT;                                                 
RUN;
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon Sep 08, 2008 7:44 pm
Reply with quote

Quote:
Didn't spot that case in the original requirement. Should have.


Yes, you're FIRED icon_lol.gif

But ...........

Click HERE to see how to use tags to make your post more easily readable
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon Sep 08, 2008 7:54 pm
Reply with quote

Quote:
If Var1 is ‘}}}}}}}}}}’ then the output should be null


You're FIRED twice icon_lol.gif icon_lol.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 08, 2008 8:09 pm
Reply with quote

Quote:
If Var1 is ‘}}}}}}}}}}’ then the output should be null
Since SAS string variables don't actually have NULL fields because they're fixed length, the output string is set to spaces in my code (which was tested, btw).
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
Search our Forums:

Back to Top