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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1072 views
  • 0 likes
  • 3 in conversation