How do I get the first part of the string using %scan

Accepted Solution Solved
Reply
Regular Contributor
Posts: 152
Accepted Solution

How do I get the first part of the string using %scan

[ Edited ]

Hello experts,

if I have a string defined as &a and I want to grab all the string prior to @ from the whole string as defined by the %macro a %put. how do I achieve the result?

the following macro a is not working...

 

 

%let a=%str(SELECT a.ITS_ORIG_STN_CD , a.ITS_ORIG_STN_DS , b.CODE_CD, b.SUB_CODE_CD, b.CODE_TYPE_GP, b.CODE_LITERAL_DS from DS_LEAP.DS_ACCUSED a INNER JOIN DS_LEAP.DS_CODE_TABLE b ON ( a.ITS_ORIG_STN_CD = b.CODE_CD ) WHERE b.CODE_TYPE_GP = '0026' AND a.ITS_ORIG_STN_DS <> b.CODE_LITERAL_DS@a);

 

%macro a;

 

%put %scan(%nrstr(&a),1,'@');

 

%mend;

%a;

 

 

Thanks


Accepted Solutions
Solution
‎05-17-2017 03:06 AM
Regular Contributor
Posts: 222

Re: How do I get the first part of the string using %scan

What are you expecting to get from %put %scan(%superq(a),2,%str(@));?
From your example string, there are no text after the '@' character.

View solution in original post


All Replies
Regular Contributor
Posts: 222

Re: How do I get the first part of the string using %scan

 

Try this,

 

%let a= %str(SELECT a.ITS_ORIG_STN_CD,a.ITS_ORIG_STN_DS,b.CODE_CD, b.SUB_CODE_CD,b.CODE_TYPE_GP,b.CODE_LITERAL_DS from DS_LEAP.DS_ACCUSED a INNER JOIN DS_LEAP.DS_CODE_TABLE b ON ( a.ITS_ORIG_STN_CD = b.CODE_CD ) WHERE b.CODE_TYPE_GP = '0026' AND a.ITS_ORIG_STN_DS <> b.CODE_LITERAL_DS@a);

%macro a;
 %put %scan(%superq(a),1,%str(@));
%mend;
%a;

Ahmed

Regular Contributor
Posts: 152

Re: How do I get the first part of the string using %scan

Posted in reply to AhmedAl_Attar
thanks for your reply but it doesn't work when you try
%put %scan(%superq(a),2,%str(@));
Solution
‎05-17-2017 03:06 AM
Regular Contributor
Posts: 222

Re: How do I get the first part of the string using %scan

What are you expecting to get from %put %scan(%superq(a),2,%str(@));?
From your example string, there are no text after the '@' character.
Super User
Posts: 5,518

Re: How do I get the first part of the string using %scan

Have you tried removing the quotes from the third parameter:  @ instead of '@'

 

The quotes aren't needed, and therefore indicate that quotes are one of the characters that %SCAN should use as a delimiter.

 

%SUPERQ (as was suggested) is a good idea as well:

 

%macro a;

 

  %put %scan(%super(a), 1, @ );

 

%mend a;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 180 views
  • 1 like
  • 3 in conversation