Hi Experts,
i got an issue while iam using scan function. i want to seperate the string with delimeter.
example is below:
%let varlist=ficc <100 ficc 100-400 ficc >400;
%macro test;
%do i=1 to 3;
%let test=%sysfunc(scan(&varlist,&i,' '));
%put &test=;
%end;
%mend;
%test;
got an errors saying scan have too many arguments ,some time uninitilized
want:
test=ficc <100
test=ficc 100-400
test=ficc >400
Thanks
Sam
you need a %to in your do loop.
There's many ways to do this, but if you know you always need the ficc why not scan with that as the delimiter instead and always add it in?
%let varlist=ficc <100 ficc 100-400 ficc >400;
%macro test;
%do i=1 %to 3;
%let test=%sysfunc(scan(&varlist,&i,'ficc'));
%put test= ficc &test;
%end;
%mend;
%test;
you need a %to in your do loop.
There's many ways to do this, but if you know you always need the ficc why not scan with that as the delimiter instead and always add it in?
%let varlist=ficc <100 ficc 100-400 ficc >400;
%macro test;
%do i=1 %to 3;
%let test=%sysfunc(scan(&varlist,&i,'ficc'));
%put test= ficc &test;
%end;
%mend;
%test;
a blank is a special character for Macro compiler. you need add %str () around it.
%let varlist=ficc <100 ficc 100-400 ficc >400;
%macro test;
%do i=1 %to 6 %by 2;
%let test=%scan(&varlist,&i,%str( ));
%let test1=%scan(&varlist,%eval(&i+1),%str( ));
%put &test &test1 ;
%end;
%mend;
%test
Ksharp
Thank you Reeza and Ksharp!!!!! Thanks for the details....
Ksharp it really Good to see you back!!!!!
Sam
Thanks. I am happy to here too . Hope I could always be here . Guys!
1)is %str( ) used here for the spaces between the names in the variable list???
a blank is a special character for Macro compiler. you need add %str () around it.
%let varlist=ficc <100 ficc 100-400 ficc >400;
%macro test;
%do i=1 %to 6 %by 2;
%let test=%scan(&varlist,&i,%str( ));
2)firstly how can the variables in a dataset be named like this(with a space in between???)??
is that allowed???
ficc <100
Thirdly,
test=%sysfunc(scan(&varlist,&i,'ficc'));
if we use ficc as a delimiter then wont it be eliminated????
when we say a delimiter is a space then it means space seperated the two words...
same way here is it not like telling ficc spereatess two words???
Who said anything about variable names?
You can do it though, using it with options validvarname=any;
then you reference it 'ficc <100'n
I am sorry about the confusion.
Thanks
1)is %str( ) used here for the spaces between the names in the variable list???
Yes.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.