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

Hi, The variable REFMATS has this information 


However, the code i have keeps outputting the first [ as a clause and would like to update the clause code to not take the first "["

 

REFMATS

[Type:ADRG, URL :, Version : , Status : , Date : Notes :,[Type:P21 Report, URL :, Version : , Status : , Date : Notes :,[Type:eSub Source Data Location, URL :, Version : , Status : , Date : Notes :,[Type:eSub Data Package Location, URL :, Version : , Status : , Date : Notes :

 

data work._ref_mat_info (label = "Reference Materials") ;
length clause $150 ;
set test.deliverables(obs=1) ;
where REFMATS ne "";
_i = 0 ;
do until(REFMATS = "") ;
_i + 1 ;
if _i >= 100 then stop ;
_pos = index(REFMATS,'[') ;
if _pos = 0 then do ;
clause = REFMATS ;
REFMATS = "" ;
end ;
else do ;
clause = substr(REFMATS,1,_pos) ;
REFMATS = substr(REFMATS,sum(_pos,1)) ;
end ;
output ;
end ;
*keep _ref_mat clause num text ;
run ;

 

The clause variable keeps outputting this and I would like the first "[" to not be taken. 

CLAUSE:

 

obs      CLAUSE

1           [

2          Type:ADRG, URL :, Version : , Status : , Date : Notes :,[

3          Type:eSub Source Data Location, URL :, Version : , Status : , Date : Notes :,[

4          Type:eSub Source Data Location, URL :, Version : , Status : , Date : Notes :,[

5          Type:eSub Data Package Location, URL :, Version : , Status : , Date : Notes :

 

 

Any help is appreciated 

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

What are you attempting to achieve, i.e. what do you want as the output for a given input. 

I'm assuming you don't want the first observation in your output ("[") and probably none of the "["

 

Here's a potential solution using the scan function

 

data want ;
	string="[Type:ADRG, URL :, Version : , Status : , Date : Notes :,[Type:P21 Report, URL :, Version : , Status : , Date : Notes :,[Type:eSub Source Data Location, URL :, Version : , Status : , Date : Notes :,[Type:eSub Data Package Location, URL :, Version : , Status : , Date : Notes :" ;
	n=1 ;
	word=scan(string,n,"[") ;
	do while (word ne "") ;
		output ;
		n=n+1 ;
		word=scan(string,n,"[") ;
	end ;
run ;

View solution in original post

2 REPLIES 2
AMSAS
SAS Super FREQ

What are you attempting to achieve, i.e. what do you want as the output for a given input. 

I'm assuming you don't want the first observation in your output ("[") and probably none of the "["

 

Here's a potential solution using the scan function

 

data want ;
	string="[Type:ADRG, URL :, Version : , Status : , Date : Notes :,[Type:P21 Report, URL :, Version : , Status : , Date : Notes :,[Type:eSub Source Data Location, URL :, Version : , Status : , Date : Notes :,[Type:eSub Data Package Location, URL :, Version : , Status : , Date : Notes :" ;
	n=1 ;
	word=scan(string,n,"[") ;
	do while (word ne "") ;
		output ;
		n=n+1 ;
		word=scan(string,n,"[") ;
	end ;
run ;
LeonidBatkhan
Lapis Lazuli | Level 10

Hi Dregerator,

Here is a pair of complementary blog posts that I wrote recently:

Hope this helps.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 567 views
  • 0 likes
  • 3 in conversation