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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.