BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
learn_SAS_23
Quartz | Level 8

Hello Team ,

 

we are having below text in the end of  XML file 

 

<link rel="next" href="http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..." /></feed>);

 

 

%macro GetFileByServerRelativeUrl (out_param=);
		%global &out_param. test1;
		%let &out_param.=;
		data _null_;
		length text $32767;
        infile "/out_countryrisk_fi.txt" DSD DLM="09"x ;
	 	input;
		test1=index( _infile_,'next');
		put 'this is to test value ' test1 ;
		call symputx("&out_param.", text);
      	run;
%put  macro variable &out_param. created with value &&&out_param. ;
		
%mend;

 %GetFileByServerRelativeUrl ( out_param=ServerUrl_new);

1. am try to search for word 'next' in the XML  using

 test1=index( _infile_,'next');  where am getting '0' as output

 

2. how to read the text only in double quotes after the word next in above string

 

1 ACCEPTED SOLUTION

Accepted Solutions
learn_SAS_23
Quartz | Level 8

Thanks every one for all your inputs , 

 

from this i could able to analyse that the input file am reading is more than 32767 , so the lines having the text (next) are truncated .

 

Here is solution , where am reading the input file morethan 32767 untill end of the file and searching for the string 'next' using find and finally extracting the text in href which are enclosed in doublequotes.  

 

data Test_dataset;
infile " /out_test.txt" lrecl=32767 recfm=f truncover;
input @1 myline $CHAR32767.;
put "the value of _infile_ is:" _infile_ ;
test1=find( _infile_,'next');
text=scan(substr(_infile_, find( _infile_,'next')+11),1,"""");
put 'this is to test value ' text;
run;

 

 

 

View solution in original post

7 REPLIES 7
Quentin
Super User

Hi, 

 

Your use of INDEX() looks fine to me, e.g. below works:

data _null_ ;
  string="<link rel=""next"" href=""http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..."" /></feed>);" ;
  test1=index(string,'next');
  put string= test1=;
run ;

 Note that your XML file likely has multiple lines, and this will be checking every line to see if it has the string "next" on in it.

 

To debug, I suggest you change your PUT statement to:

put 'this is to test value ' test1= _infile_ ;

That should let you check that the _infile_ variable has the value you intend.

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
learn_SAS_23
Quartz | Level 8
thanks for quick reply,
is there any way to double quote whole text in a file , as i observe you enclosed the double quoted string in double quote like this ""next""
Quentin
Super User
Hi, you don't need to double quote the values you read from the text file. I had to do it because I was using the string on an assignment statement, so I used double quote marks to define the string, and then inside the string used double double quotes. Put if you run my code, you will see the PUT statement shows that the value of STRING does not have double double quotes in it. Because the assignment statement translates ""next"" to "next".
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Quentin
Super User

Your original code works for me.  Here is an example where I write a file, and then read in the file using your original code.  I added a PUT statement to show the value of _infile_.

 

*generate an input file;
data _null_ ;
  file "Q:\junk\foo.txt" ;
  put "<link rel=""next"" href=""http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..."" /></feed>);" ;
  put "hello world" ;
run ; 


*Read in the file ;
data _null_;
  infile "Q:\junk\foo.txt" DSD DLM="09"x ;
  input;
  test1=index( _infile_,'next');
  put "the value of _infile_ is:"  _infile_  ;
  put 'this is to test value ' test1;
run;

Log is:

10   *Read in the file ;
11   data _null_;
12     infile "Q:\junk\foo.txt" DSD DLM="09"x ;
13     input;
14     test1=index( _infile_,'next');
15     put "the value of _infile_ is:"  _infile_  ;
16     put 'this is to test value ' test1;
17   run;

NOTE: The infile "Q:\junk\foo.txt" is:
      Filename=Q:\junk\foo.txt,
      RECFM=V,LRECL=32767,File Size (bytes)=154,
      Last Modified=17Aug2022:08:03:28,
      Create Time=17Aug2022:07:54:47

the value of _infile_ is:
<link rel="next" href="http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%
20test%20test%20test'..." /></feed>);
this is to test value 12
the value of _infile_ is:hello world
this is to test value 0
NOTE: 2 records were read from the infile "Q:\junk\foo.txt".
      The minimum record length was 11.
      The maximum record length was 139.
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Astounding
PROC Star

Here's a theory as to the cause ... it should be easy for you to test.

 

When your INPUT statement ends, it releases the current line of raw data.  That updates the value of _INFILE_.  So make a small change to your program to hold on to the current line of raw data just a little bit longer:  Where you have:

input;

change it to:

input @;
Tom
Super User Tom
Super User

Are you just looking for the HREF= values that appear after the NEXT string?

data want ;
  infile "/out_countryrisk_fi.txt" DSD DLM='<= >' ;
  input @'"next"' @ '"href"=' text :$32767. @@ ;
run;
learn_SAS_23
Quartz | Level 8

Thanks every one for all your inputs , 

 

from this i could able to analyse that the input file am reading is more than 32767 , so the lines having the text (next) are truncated .

 

Here is solution , where am reading the input file morethan 32767 untill end of the file and searching for the string 'next' using find and finally extracting the text in href which are enclosed in doublequotes.  

 

data Test_dataset;
infile " /out_test.txt" lrecl=32767 recfm=f truncover;
input @1 myline $CHAR32767.;
put "the value of _infile_ is:" _infile_ ;
test1=find( _infile_,'next');
text=scan(substr(_infile_, find( _infile_,'next')+11),1,"""");
put 'this is to test value ' text;
run;

 

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 969 views
  • 0 likes
  • 4 in conversation