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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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