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 -

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1073 views
  • 3 likes
  • 4 in conversation