Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: SAS Requirement - remove the trailing ‘{‘ from a variabl
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    Post subject: Reply to: SAS Requirement - remove the trailing ‘{‘ from
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Mon Sep 08, 2008 4:31 pm    Post subject: Reply to: SAS Requirement - remove the trailing ‘{‘ from
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: 8593
Location: Back in jolly old England

PostPosted: Mon Sep 08, 2008 4:44 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: SAS Requirement - remove the trailing ‘{‘ from
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    Post subject:
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    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Mon Sep 08, 2008 6:39 pm    Post subject:
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: 7931
Location: Bellevue, IA

PostPosted: Mon Sep 08, 2008 6:42 pm    Post subject:
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    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Mon Sep 08, 2008 7:44 pm    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Mon Sep 08, 2008 7:54 pm    Post subject:
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: 7931
Location: Bellevue, IA

PostPosted: Mon Sep 08, 2008 8:09 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Mainframe Developer requirement in Ku... capricorn Mainframe Jobs 0 Sun Oct 23, 2016 3:49 pm
No new posts Cards mainframe developer requirement... capricorn Mainframe Jobs 0 Sun Sep 11, 2016 9:57 am
No new posts Remove Special Characters from Mainfr... Rodger Zhang All Other Mainframe Topics 6 Wed Jul 06, 2016 1:12 am
This topic is locked: you cannot edit posts or make replies. Urgent Requirement in CTS Chennai. Mahi_e Mainframe Jobs 0 Wed Feb 17, 2016 3:52 pm
No new posts Remove header only knobi SYNCSORT 5 Mon Feb 15, 2016 10:42 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us