Help using Base SAS procedures

Scan Function

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

Scan Function


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


Accepted Solutions
Solution
‎04-24-2013 11:15 AM
Super User
Posts: 17,818

Re: Scan Function

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


All Replies
Solution
‎04-24-2013 11:15 AM
Super User
Posts: 17,818

Re: Scan Function

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;

Super User
Posts: 9,676

Re: Scan Function

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

Regular Contributor
Posts: 168

Re: Scan Function

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

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

Sam

Super User
Posts: 9,676

Re: Scan Function

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

Super Contributor
Posts: 1,040

Re: Scan Function

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

Super User
Posts: 17,818

Re: Scan Function

Who said anything about variable names?

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

then you reference it 'ficc <100'n 

Super Contributor
Posts: 1,040

Re: Scan Function

I am sorry about the confusion.

Thanks

Super User
Posts: 9,676

Re: Scan Function

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

Yes.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 365 views
  • 4 likes
  • 4 in conversation