BookmarkSubscribeRSS Feed
SASSLICK001
Obsidian | Level 7

Hello All

I have the following code and trying to extract first word (QTcF) how can i achieve this?

data x;

input seq param $ 2-80;

datalines;

1 QTcB - Bazett's Correction Formula (msec)

;

run;

data y;

set x;

call symput ("param", cats(param));

run;

%put &param;  ( this is not resolved in log)

When i am doing the following way i get an error in the log

%let x = %scan("&param",1,-));

%put &x;

ERROR: Open code statement recursion detected.

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

First issue is that you are unable to create a macro variable where the value has a unbalanced quote. To avoid this you need to try the following code

data y;

set x;

call symputx('param', quote(trim(param)));

run;

%put &param;

it will create the param macro variable with value. Then to get the QTCB please try

%let x = %substr(%qsysfunc(scan(&param,1,'-')),2);

%put &x;

First it will extract the QTCB and then it will remove the first quote by substr.

Please try and let me know if it was helpful.

Thanks,

Jag

Thanks,
Jag
Quentin
Super User

Actually it's okay to have an unmatched quote inside a macro variable, as long as you macro quote it when you use it.  The following should work:

%let x = %scan(%superq(param),1,-) ;

Worked for me on free SAS University Edition running on AWS. So cool to have that.  Thank you SAS.

--Q.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 715 views
  • 0 likes
  • 3 in conversation