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
 

 

Extracting delimited values - SAS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1459
Location: Azeroth

PostPosted: Tue Jun 21, 2011 7:17 pm    Post subject: Extracting delimited values - SAS
Reply with quote

Hello,
I am trying to extract the 2nd word from a string in SAS.
The words are delimited by ,+ (both of them, not ',' or '+')

For input data
Code:
111,22+333,+444

the second word that needs to be extracted is "444"

I tried the below code, but scan function treats "," or "+" as delimiters not a combination of them.
Code:
Code:
data practice;           
var1 = '111,22+333,+444';
val = scan(var1,2,',+'); 
put val=;                 
run;

Output:
Code:
val=22


Please let me know how this could be done. Thanks.
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: Tue Jun 21, 2011 7:27 pm    Post subject:
Reply with quote

Have you looked at DSD and DLM='+', just a first thought
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7936
Location: Bellevue, IA

PostPosted: Tue Jun 21, 2011 7:28 pm    Post subject:
Reply with quote

Code:
data practice;           
var1 = '111,22+333,+444';
delimloc = index(var1, ',+');
if delimloc > 0 then val = substr(var1, delimloc+2);
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1459
Location: Azeroth

PostPosted: Tue Jun 21, 2011 7:57 pm    Post subject:
Reply with quote

@Robert, Thanks for your code, it works well.
@Expat, Thanks.. I was trying to extract data from a variable, so DLM & DSD infile options were not useful in this scenario.

Regards,
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Jun 21, 2011 8:44 pm    Post subject:
Reply with quote

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm
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: Tue Jun 21, 2011 9:42 pm    Post subject:
Reply with quote

Sorry, I read your post in a hurry.

tut tut, should know better next time
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1459
Location: Azeroth

PostPosted: Wed Jun 22, 2011 12:19 pm    Post subject:
Reply with quote

@Peter Thanks for the link,
I had a look at the link before starting the topic, but I think the modifiers for SCAN function applies for latest release of SAS :S ..
We have SAS 9.1 and when I use the modifiers for the scan function it says,

Code:
ERROR 72-185: The COUNTW function call has too many arguments.
                                                             
8       do count = 1 to nwords;                               
9          word = scan(string, count, delim, modif);         
                  ----                                       
                  72                                         
ERROR 72-185: The SCAN function call has too many arguments. 


For the program,
Code:
data comma;                                                 
   keep count word;                                         
   length word $30;                                         
   string = ',leading, trailing,and multiple,,delimiters,,';
   delim = ',';                                             
   modif = 'mo';                                             
   nwords = countw(string, delim, modif);                   
   do count = 1 to nwords;                                   
      word = scan(string, count, delim, modif);             
      output;                                               
   end;                                                     
run;                                                         
                                                             
proc print data=comma noobs;                                 
run;                                                         


Regards,
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1459
Location: Azeroth

PostPosted: Wed Jun 22, 2011 12:26 pm    Post subject:
Reply with quote

Hello,

For the benefit of sharing, There was one more function which was useful in this scenario along with Robert's solution,

Code:
data practice;               
var1 = '111,22+333,+444';     
temp = tranwrd(var1,',+','~');
val = scan(temp,2,'~');       
put val=;                     
run;
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Jun 22, 2011 2:09 pm    Post subject:
Reply with quote

Quote:

I had a look at the link before starting the topic, but I think the modifiers for SCAN function applies for latest release of SAS :S ..
We have SAS 9.1


SAS 9.1 :

http://support.sas.com/publishing/pubcat/chaps/59343.pdf

Search for CALL SCAN in that PDF.
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 -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sort Card to Remove Duplicate records... raj4neo SYNCSORT 2 Wed Jan 25, 2017 4:44 am
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Overlaying one set of charater values... Kevin Lindsley SYNCSORT 7 Sat Nov 05, 2016 3:21 am
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am


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