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

Hallo.

 

I have a file '~/test.sas' which contains one line

    %metalibm(inlibdw);             * Bankdata DW;

when i run

data test2;
infile "~/test.sas" truncover;
input line $char100.;
commentEnd=prxparse('/(\*\/|;$)/');
end_=prxmatch(commentEnd,line);
run;

I get end_=0.But if I input the line in a dataset

data test3;
line=' %metalibm(inlibdw); * Bankdata DW;';
commentEnd=prxparse('/(\*\/|;$)/');
end_=prxmatch(commentEnd,line);
run;

I get end_=50 wich is corret.

 

Any idea of why this happens?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You seem to be comparing apples to oranges here.

Change your second data step to define LINE as being of length $100 so that it matches how SAS guessed you wanted the variable defined in the first data step.

 

Your REGEX needs to account for the trailing spaces that will be present in a SAS variable.  

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You seem to be comparing apples to oranges here.

Change your second data step to define LINE as being of length $100 so that it matches how SAS guessed you wanted the variable defined in the first data step.

 

Your REGEX needs to account for the trailing spaces that will be present in a SAS variable.  

Oligolas
Barite | Level 11

Hi,

consider the trailing blanks in your line variable with length=100.

You are expecting a semi-colon at end of line, but you have a semi-colon followed by blanks instead

Consider adding \s* to your regex or use strip(line) in prxmatch

 

data test3;
line=' %metalibm(inlibdw); * Bankdata DW;';
commentEnd=prxparse('/(\*\/|;$)/');
end_=prxmatch(commentEnd,strip(line));
run;

 Edit: or trim(line) like @data_null__ said

________________________

- Cheers -

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 635 views
  • 3 likes
  • 4 in conversation