BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sam369
Obsidian | Level 7


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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

8 REPLIES 8
Reeza
Super User

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;

Ksharp
Super User

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

sam369
Obsidian | Level 7

Thank you Reeza and Ksharp!!!!! Thanks for the details....

Ksharp it really Good to see you back!!!!!

Sam

Ksharp
Super User

Thanks. I am happy to here too . Hope I could always be here . Guys!

robertrao
Quartz | Level 8

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???

Reeza
Super User

Who said anything about variable names?

You can do it though, using it with options validvarname=any;

then you reference it 'ficc <100'n 

robertrao
Quartz | Level 8

I am sorry about the confusion.

Thanks

Ksharp
Super User

1)is %str( ) used here for the spaces between the names in the variable list???

Yes.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 8 replies
  • 1025 views
  • 4 likes
  • 4 in conversation