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
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
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.